import os
file_dir_path = "D:/Test/list"
for dirName, subdirList, fileList in os.walk(file_dir_path):
if fileList != []:
jpg_name = fileList[0]
if jpg_name!='Thumbs.db':
continue
fileList的结果:['Rope01.jpg','Rope02.jpg','Thumbs.db']
在fileList中,我想排除要列出的Thumbs.db。
答案 0 :(得分:0)
fileList
是os.walk
为其遍历的每个目录返回的文件列表。
您只需要过滤掉.db文件名:
for dirName, subdirList, fileList in os.walk(file_dir_path):
fileList = [x for x in fileList if x != 'Thumbs.db']
# now fileList contains everything in dirName but Thumbs.db