python高效过滤出文件夹下指定文件名结尾的文件实例
如下所示:
import os def anyTrue(predicate, sequence): return True in map(predicate, sequence) def filterFiles(folder, exts): for fileName in os.listdir(folder): if os.path.isdir(folder + '/' + fileName): filterFiles(folder + '/' + fileName, exts) elif anyTrue(fileName.endswith, exts): print fileName exts = ['.md', '.yml', '.rst'] filterFiles('D:\\Twisted\\twisted-trunk', exts) import os import time from itertools import imap def anyTrue(predicate, sequence): return True in imap (predicate, sequence) def filterFiles(folder, exts): for fileName in os.listdir(folder): if os.path.isdir(folder + '/' + fileName): filterFiles(folder + '/' + fileName, exts) elif anyTrue(fileName.endswith, exts): print fileName start = time.time() exts = ['.md', '.yml', '.rst'] filterFiles('D:\\Twisted\\twisted-trunk', exts) print('total time=%f' %(time.time()- start))
相关推荐
FlySky 2020-11-02
逍遥友 2020-10-26
taiyangshenniao 2020-10-05
flycony 2020-09-23
jacktangj 2020-09-18
YENCSDN 2020-09-15
lsjweiyi 2020-09-14
digwtx 2020-09-14
拾毅者 2020-09-14
zlxcsdn 2020-09-13
weiiron 2020-08-17
amazingbo 2020-08-16
郗瑞强 2020-08-16
lispython 2020-08-16
fengling 2020-08-15
xiesheng 2020-08-02
葫芦小金刚 2020-07-28
StevenSun空间 2020-07-26