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

yipeiwu_com4年前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元字典 字典(dictionary)是除列表以外python之中最灵活的内置数据结构类型。列表是有序的对象结合,字典是无序的对象集合。 两者之间的区别在于:字典当中的元素是通...

Pycharm中Python环境配置常见问题解析

Pycharm中Python环境配置常见问题解析

本文实例讲述了Pycharm中Python环境配置常见问题。分享给大家供大家参考,具体如下: 1、问题的发现 最近在用Pycharm下的命令行工具安装、运行jupyter noteboo...

python pillow模块使用方法详解

pillow Pillow是PIL的一个派生分支,但如今已经发展成为比PIL本身更具活力的图像处理库。pillow可以说已经取代了PIL,将其封装成python的库(pip即可安装),...

python五子棋游戏的设计与实现

这个python的小案例是五子棋游戏的实现,在这个案例中,我们可以实现五子棋游戏的两个玩家在指定的位置落子,画出落子后的棋盘,并且根据函数判断出输赢的功能。 这个案例的思路如下所示: 首...

深入分析在Python模块顶层运行的代码引起的一个Bug

然后我们在Interactive Python prompt中测试了一下: >>> import subprocess >>> subproc...