#coding:utf-8 import threading import os import time def main(name,*types): for root,dirs,files in os.walk(name): for f in files: if os.path.isfile(os.path.join(root,f)) and os.path.splitext(f)[1][1:] in types: print os.path.join(root,f) if __name__ == '__main__': t1=time.time() #加入线程,搜索D盘 以.sql、.zip结尾的文件 t = threading.Thread(target=main,args=(r"D:\\","sql","zip")) t.start() t.join() #计算执行时间 print time.time()-t1
#以获取mp3文件为例
import os
name=r"E:\KwDownloadx\song"
tag=['.mp3']
def getmp3(dirname,label):
mp3list = [os.path.normcase(i) for i in os.listdir(dirname)]
print
[ os.path.join(dirname,k) for k in mp3list if os.path.splitext(k)[1] in label] #过滤指定的文件类型
## if os.path.splitext(k)[1] in label: #过滤指定的文件类型
## print os.path.join(dirname,k)
##
getmp3 (name,tag)
版权声明:本文为博主原创文章,未经博主允许不得转载。