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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-17 我要评论
想了解python 查找文件夹下所有文件 实现代码的相关内容吗,在本文为您仔细讲解python 查找文件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:python,查找文件,下面大家一起来学习吧。
复制代码 代码如下:

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

final_file_list = []
print base
cur_list = os.listdir(base)
for item in cur_list:
if item == ".svn":
continue

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

# print full_path
bfile = os.path.isfile(item)
if os.path.isfile(full_path):
if re_file.search(full_path):
final_file_list.append(full_path)
else:
final_file_list += find_file_by_pattern(pattern, full_path)
return final_file_list

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们