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

yipeiwu_com6年前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

相关文章

Django Rest framework权限的详细用法

Django Rest framework权限的详细用法

前言 我们都听过权限,那么权限到底是做什么的呢. 我们都有博客,或者去一些论坛,一定知道管理员这个角色, 比如我们申请博客的时候,一定要向管理员申请,也就是说管理员会有一些特殊的权利,是...

浅谈django开发者模式中的autoreload是如何实现的

在开发django应用的过程中,使用开发者模式启动服务是特别方便的一件事,只需要 python manage.py runserver 就可以运行服务,并且提供了非常人性化的autore...

python 叠加等边三角形的绘制的实现

python 叠加等边三角形的绘制的实现

python语言程序设计基础 习题2.5 import turtle def drawTriangle(num,len,flag):#flag用来调整画三角形的方向 flag...

详解Python的Django框架中manage命令的使用与扩展

【简介】 django-admin.py是Django的一个用于管理任务的命令行工具。本文将描述它的大概用法。 另外,在每一个Django project中都会有一个manage.py。...

python中的print()输出

1.普通的输出: print(str)#str是任意一个字符串,数字··· 2.格式化输出: print('1,2,%s,%d'%('asd',4)) 1,2,asd,4 与C语...