如何找到一个目录下所有.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怎么求整数n的阶乘?

Python怎么把列表转化为字符串

Python用什么文本编辑器

Python中gensim库word2vec的使用

Python2.7和3.7的区别

Python基础知识一:网络通信数据传输

Python学完基础学什么

spyder和Python有什么关系

Python如何调用c语言函数的使用详解

Python如何实现自动访问网页功能

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




打赏

取消

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

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

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

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

评论

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