遍历目录树

  • Post author:
  • Post category:其他


# 遍历目录树

import os

for folderName,subFolders,fileNames in os.walk(‘E:\\Pycharm\\Python编程快速上手—让繁琐工作自动化’):

print(‘The current folder is ‘ + folderName)

for subFolder in subFolders: # 遍历当前目录下所有子目录

print(‘SUBFOLDER OF ‘ + folderName + ‘: ‘ +  subFolder)

for fileName in fileNames: # 遍历当前目录下所有文件

print(‘FILE INSIDE ‘ + folderName + ‘:’ + fileName)

print(”)



版权声明:本文为qq_42766312原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。