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中字符串转换成数字 (方法1) 类中进行导入:import string str='555' num=string.atoi(str) num即为str转换成的数字...

Python 按字典dict的键排序,并取出相应的键值放于list中的实例

方法一: def dict_to_numpy_method1(dict): dict_sorted=sorted(dict.iteritems(), key=lambda d:d[...

Python 操作mysql数据库查询之fetchone(), fetchmany(), fetchall()用法示例

本文实例讲述了Python 操作mysql数据库查询之fetchone(), fetchmany(), fetchall()用法。分享给大家供大家参考,具体如下: demo.py(查询,...

pd.DataFrame统计各列数值多少的实例

如下所示: .count() #非空元素计算 .min() a #最小值 .max() #最大值 .idxmin() #最小值的位置,类似于R中的which.min函...

对Django外键关系的描述

注:本文需要你有一定的数据库知识,本文的数据库语法使用mysql书写 Django中,跟外键有关的关系有三种,下面来一一介绍。 OneToManyField 这种最好理解,说白了就是最普...