Go directly to the code, this code can be put in the thread, otherwise, if there are too many files, it will be time-consuming
import os
# 遍历文件夹
def walkFile(file):
for root, dirs, files in os.walk(file):
# root 表示当前正在访问的文件夹路径
# dirs 表示该文件夹下的子目录名list
# files 表示该文件夹下的文件list
# 遍历文件
for f in files:
print("文件:",os.path.join(root, f))
#条件选取 if f.endswith('.xls'):
# 遍历所有的文件夹
for d in dirs:
print("目录:",os.path.join(root, d))
walkFile("e:\pythontest")