Python如何找到一个目录下所有.txt文件【面试题详解】

今天爱分享给大家带来Python如何找到一个目录下所有.txt文件【面试题详解】,希望能够帮助到大家。
使用glob


import glob
import os
os.chdir("/mydir")
for files in glob.glob("*.txt"):
    print files

或者遍历目录


import os
for r,d,f in os.walk("/mydir"):
    for files in f:
        if files.endswith(".txt"):
            print os.path.join(r,files)

原文链接:http://blog.itblood.com/4404.html,转载请注明出处。
0
森林之庭~小镇牧场生活~V1.2.2 内嵌AI汉化版[更新][750M] [精品RPG/汉化]
森林之庭~小镇牧场生活~V1.2.2 内嵌AI汉化版[更新][750M] [精品RPG/汉化]
3分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?