python 查找文件夹下所有文件 实现代码
python 查找文件夹下所有文件 实现代码
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:deffind_file_by_pattern(pattern='.*',base=".",circle=True):''...

复制代码 代码如下:

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

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新python学习
热门python学习
脚本专栏子分类