用python-os模块实现文件查找

受到上一篇博客的启发,对它进行了少量的修改,就可以用它来进行文件的查找

#-*- coding:utf-8 -*-
import time
import os
import re
flag = 0
def findfile(filename,path):
    for root,dirs,files in os.walk(path):
        for file in files:
            if file == filename:
                print os.path.join(root,file)
                print "Matched!"
                flag = 1
                break
    if flag == 0:
        print "None Matched"
        
        
src = r'19 - 1 - Summary and Thank You (5 min).mp4'
dest = r'F:'
start = time.time()
findfile(src,dest)
c = time.time()-start
print ("%0.2f s"%c)


用python-os模块实现文件查找_第1张图片

我觉得搜索的还蛮快的,虽然说效率肯定不高。



你可能感兴趣的:(Python,python,文件操作)