python 遍历目录(包括子目录)下所有文件的实例
作者:一些和风旭日的日子 时间:2022-05-01 00:01:52
如下所示:
def list_all_files(rootdir):
import os
_files = []
list = os.listdir(rootdir) #列出文件夹下所有的目录与文件
for i in range(0,len(list)):
path = os.path.join(rootdir,list[i])
if os.path.isdir(path):
_files.extend(list_all_files(path))
if os.path.isfile(path):
_files.append(path)
return _files
_fs = list_all_files('./资料')
#将第一阶段的文件遍历出来
_k = filter(lambda x:re.compile(r'stage2.txt').search(x),_fs)
来源:https://blog.csdn.net/liubenq/article/details/79026991
标签:python,遍历,目录,子目录
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
高考要来啦!用Python爬取历年高考数据并分析
2021-06-10 04:08:25
![](https://img.aspxhome.com/file/2023/9/68439_0s.jpg)
Go语言实现的树形结构数据比较算法实例
2023-08-06 18:18:39
解析xml字符串的函数
2008-06-10 12:37:00
用Python分析3天破10亿的《我不是药神》到底神在哪?
2023-04-29 06:16:26
![](https://img.aspxhome.com/file/2023/0/91930_0s.jpg)
python自动化调用百度api解决验证码
2023-03-18 19:21:27
![](https://img.aspxhome.com/file/2023/1/123681_0s.png)
磁盘缓存专题之一 缓存命中和缓存未命中&缓存与缓冲间的差异
2012-10-07 11:02:46
如何用Python绘制3D柱形图
2022-12-19 04:22:04
![](https://img.aspxhome.com/file/2023/2/97332_0s.png)
Oracle相关组件版本信息的介绍
2023-07-14 09:19:53
![](https://img.aspxhome.com/file/2023/4/64454_0s.png)
Keras中的多分类损失函数用法categorical_crossentropy
2023-06-23 12:25:37
![](https://img.aspxhome.com/file/2023/5/63935_0s.jpg)
pygame可视化幸运大转盘实现
2021-03-01 05:22:11
![](https://img.aspxhome.com/file/2023/7/79607_0s.png)
Golang二维数组的使用方式
2023-07-21 07:29:16
Python使用RSA库加密和解密
2023-04-23 02:46:29
用Frontpage设计网站主页
2008-10-23 13:44:00
Oracle 10g client 安装图解教程
2023-07-13 20:40:10
![](https://img.aspxhome.com/file/2023/2/64462_0s.png)
python 移除字符串尾部的数字方法
2023-03-18 19:38:21
Python 数据结构之堆栈实例代码
2023-10-30 07:27:43
MySQL转义字符
2011-06-19 16:06:04
python工具快速为音视频自动生成字幕(使用说明)
2021-04-14 15:15:26
php中instanceof 与 is_a()区别分析
2023-11-19 06:04:56
asp 过滤尖括号内所有内容的正则代码
2011-04-03 10:40:00