DDR爱好者之家 Design By 杰米

如下所示:

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高效过滤出文件夹下指定文件名结尾的文件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米