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

相关文章

Python二分法搜索算法实例分析

本文实例分析了Python二分法搜索算法。分享给大家供大家参考。具体分析如下: 今天看书时,书上提到二分法虽然道理简单,大家一听就明白但是真正能一次性写出别出错的实现还是比较难的,即使给...

Python干货:分享Python绘制六种可视化图表

Python干货:分享Python绘制六种可视化图表

可视化图表,有相当多种,但常见的也就下面几种,其他比较复杂一点,大都也是基于如下几种进行组合,变换出来的。对于初学者来说,很容易被这官网上众多的图表类型给吓着了,由于种类太多,几种图表的...

python实现telnet客户端的方法

本文实例讲述了python实现telnet客户端的方法。分享给大家供大家参考。具体如下: python实现的telnet客户端程序,python自带一个telnetlib模块,可以通过其...

Pytorch 实现冻结指定卷积层的参数

python代码 for i, para in enumerate(self._net.module.features.parameters()): if i &...

Python中装饰器高级用法详解

在Python中,装饰器一般用来修饰函数,实现公共功能,达到代码复用的目的。在函数定义前加上@xxxx,然后函数就注入了某些行为,很神奇!然而,这只是语法糖而已。 场景 假设,有一些工作...