python高效过滤出文件夹下指定文件名结尾的文件实例
程序员文章站
2022-09-11 20:52:12
如下所示:
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高效过滤出文件夹下指定文件名结尾的文件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
上一篇: 使用Scrapy爬取动态数据
下一篇: MySQL之prepare用法