zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python查找文件夹下所有文件实现代码

Python文件代码 实现 所有 查找文件
2023-06-13 09:14:10 时间
复制代码代码如下:

deffind_file_by_pattern(pattern=".*",base=".",circle=True):
"""""查找给定文件夹下面所有"""
re_file=re.compile(pattern)
ifbase==".":
base=os.getcwd()

final_file_list=[]
printbase
cur_list=os.listdir(base)
foritemincur_list:
ifitem==".svn":
continue

full_path=os.path.join(base,item)
iffull_path.endswith(".doc")or\
full_path.endswith(".bmp")or\
full_path.endswith(".wpt")or\
full_path.endswith(".dot"):
continue

#printfull_path
bfile=os.path.isfile(item)
ifos.path.isfile(full_path):
ifre_file.search(full_path):
final_file_list.append(full_path)
else:
final_file_list+=find_file_by_pattern(pattern,full_path)
returnfinal_file_list