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

yipeiwu_com5年前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判断IP地址合法性的方法实例

使用Python判断IP地址合法性的方法实例

一、使用方法和执行效果请看图:二、python实现代码:复制代码 代码如下:[root@yang python]# vi check_ip.py #!/usr/bin/python im...

python选取特定列 pandas iloc,loc,icol的使用详解(列切片及行切片)

df是一个dataframe,列名为A B C D 具体值如下: A B C D 0 ss 小红 8 1 aa 小明 d 4 f f 6 ak 小紫 7 dataframe里的属性是不定...

python使用rsa加密算法模块模拟新浪微博登录

PC登录新浪微博时,在客户端用js预先对用户名、密码都进行了加密,而且在POST之前会GET一组参数,这也将作为POST_DATA的一部分。这样,就不能用通常的那种简单方法来模拟POST...

聊聊Python中的pypy

聊聊Python中的pypy

PyPy是一个虚拟机项目,主要分为两部分:一个Python的实现和 一个编译器 PyPy的第一部分: 用Python实现的Python   其实这么说并不准确,准确得说应该是用rPy...

django中账号密码验证登陆功能的实现方法

django中账号密码验证登陆功能的实现方法

今天分享一下django的账号密码登陆,前端发送ajax请求,将用户名和密码信息发送到后端处理,后端将前端发送过来的数据跟数据库进行过滤匹配,成功就跳转指定页面,否则就把相对应的错误信息...