import os
def EnumPathFiles(path, callback):
if not os.path.isdir(path):
print('Error:"',path,'" is not a directory or does not exist.')
return
list_dirs = os.walk(path)
for root, dirs, files in list_dirs:
for d in dirs:
EnumPathFiles(os.path.join(root, d), callback)
for f in files:
callback(root, f)
def callback1(path, filename):
print(path+'\\'+filename)
if __name__ == '__main__':
EnumPathFiles(r'D:\Projects\python', callback1)
python 遍历文件夹及子文件夹
最新推荐文章于 2024-07-15 20:51:08 发布