如何找到一个目录下所有.txt文件


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

import os

root = "H:\\ab123"

def findtxt(path, ret):

    """Finding the *.txt file in specify path"""

    filelist = os.listdir(path)

    for filename in filelist:

        de_path = os.path.join(path, filename)

        if os.path.isfile(de_path):

            if de_path.endswith(".txt"): #Specify to find the txt file.

                ret.append(de_path)

        else:

            findtxt(de_path, ret)

  

ret = []

findtxt(root, ret)

for path in ret:

    print(path)

以上就是如何找到一个目录下所有.txt文件的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python的五个特点

Python怎么排序列表

Python阶乘求和的方法

Python可以用来干什么?

怎么安装Python

ubuntu怎么安装Python

Python 拷贝特定后缀名文件,并保留原始目录结构的实例

linux下修改Python命令的方法示例(附代码)

Python中print与return区别

Python中如何安装pip

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...