import os, time, fnmatch
from docx import Document
class search:
def __init__(self, path, search_string, file_filter):
self.search_path = path
self.search_string = search_string
self.file_filter = file_filter
print ("Search %s in %s..." % (
self.search_string, self.search_path
) )
print ("_" * 80)
time_begin = time.time()
file_count = self.walk()
print ("_" * 80)
print ("%s files searched in %0.2fsec." % (
file_count, (time.time() - time_begin)
))
#遍历所有的文件,记录文件数量
def walk(self):
file_count = 0
for root, dirlist, filelist in os.walk(self.search_path, followlinks=True):
for filename in filelist:
for file_filter in self.file_filter:
if fnmatch.fnmatch(filename, file_filter):
s