python高效过滤出文件夹下指定文件名结尾的文件实例
程序员文章站
2022-05-10 22:14:38
如下所示:
import os
def anytrue(predicate, sequence):
return true in map(predicat...
如下所示:
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))
以上这篇python高效过滤出文件夹下指定文件名结尾的文件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
上一篇: 程序员那些悲催的事儿