#encoding:utf-8
import os
import fnmatch
class find_file():
def is_file_match(self,filename,patterns):
for pattern in patterns:
if fnmatch.fnmatch(filename,pattern):
return True
return False
def find_specific_files(self,root,patterns=['*'],exclude_dirs=[]):
for root,dirnames,filenames in os.walk(root):
for filename in filenames:
if self.is_file_match(filename,patterns):
yield os.path.join(root,filename)
for d in exclude_dirs:
if d in dirnames:
dirnames.remove(d)
python 遍历文件系统,查找符合条件的文件,带过滤功能
最新推荐文章于 2022-07-17 15:12:31 发布