您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2024/5/3 14:32:49发布35次查看
代码如下:
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
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product