import os
def searchDirFile(rootDir, fileList, fileType):
for dir_or_file in os.listdir(rootDir):
filePath = os.path.join(rootDir, dir_or_file)
if os.path.isfile(filePath):
if filePath[-len(fileType):] == fileType:
fileList.append(filePath)
else:
continue
elif os.path.isdir(filePath):
searchDirFile(filePath, fileList, fileType)
else:
print('not file and dir '+os.path.basename(filePath))
print(fileList)
return fileList
fileList = list()
path = '.\data'
searchDirFile(path, fileList, '.xlsx')
.xlsx是文件类型可修改,最后类型文件路径都在filelist的列表里。