使用Python在指定目录搜索指定文件名,python文件名,# -*- coding
文章由Byrx.net分享于2019-03-23 04:03:17
使用Python在指定目录搜索指定文件名,python文件名,# -*- coding
# -*- coding: utf-8 -*-'''Created on 2014年12月1日@author: zhrb'''import oscount = 0def search(dstDir,fileName): global count #files = [os.path.join(dstDir,x) for x in os.listdir(dstDir)] for y in os.listdir(dstDir): absPath = os.path.join(dstDir,y) if os.path.isdir(absPath): try: search(absPath,fileName) except BaseException, e: continue elif (os.path.isfile(absPath) and os.path.split(absPath)[1].lower()==fileName.lower()): count +=1 print('found %s '%absPath.decode('gbk').encode('utf-8'))search('d:\\','1.jpg')print("%d founded"%count)
评论关闭