import os import os.path f=open("Shouldlist.txt") ShouldList=[] while 1: line =f.readline().strip('\n') # print line if not line: break ShouldList.append(line) # print ShouldList rootdir="Z:\GETOT_BW" ArriveFile='' for parent,dirnames,filenames in os.walk(rootdir): ArriveFile=' '.join(filenames) # print ArriveFile ArriveNumber=0 for Item in ShouldList: if(ArriveFile.find(Item)>0): ArriveNumber+=1 else: pass print ArriveNumber #print ShouldList[1] #print ArriveFile[254:274]
此段代码主要是检索特定目录的所有文件,并对其进行检测,判断是否应到的file到到了。
原文地址:http://blog.csdn.net/ling1510/article/details/42027625