Python 遍历文件夹中的指定类型文件

来源:互联网 发布:淘宝运营的工作坑不坑 编辑:程序博客网 时间:2024/05/16 23:51

首先罗列一下os.path模块的相关函数:http://blog.csdn.net/yh0503/article/details/24737185

python模块之codecs http://blog.csdn.net/suofiya2008/article/details/5579413

#-*- coding:utf-8 -*-import os,codecs#--------------------------# param path 要搜索文件的目录# param t 保存文件的列表def findfiles(path, t):    files = os.listdir(path);    for f in files:        npath = path + '/' + f;        if(os.path.isfile(npath)):            if(os.path.splitext(npath)[1] ==".txt"):                t.append(npath);        if(os.path.isdir(npath)):            if (f[0] == '.'):                pass;            else:                findfiles(npath, t);    return;                        t = [];#path = "F:/test_lua/Resources/hd/Images";path = "C:/test1";findfiles(unicode(path, 'utf8'), t);for fn in t:    print(fn);


0 0
原创粉丝点击