python获取指定路径下所有指定后缀文件的方法,
python获取指定路径下所有指定后缀文件的方法,
本文实例讲述了python获取指定路径下所有指定后缀文件的方法。分享给大家供大家参考。具体实现方法如下:
# 获取指定路径下所有指定后缀的文件 # dir 指定路径 # ext 指定后缀,链表&不需要带点 或者不指定。例子:['xml', 'java'] def GetFileFromThisRootDir(dir,ext = None): allfiles = [] needExtFilter = (ext != None) for root,dirs,files in os.walk(dir): for filespath in files: filepath = os.path.join(root, filespath) extension = os.path.splitext(filepath)[1][1:] if needExtFilter and extension in ext: allfiles.append(filepath) elif not needExtFilter: allfiles.append(filepath) return allfiles
希望本文所述对大家的Python程序设计有所帮助。
相关内容
- python使用正则表达式提取网页URL的方法,python正则表达
- python实现查找excel里某一列重复数据并且剔除后打印的
- Python同时向控制台和文件输出日志logging的方法,
- python使用urllib2提交http post请求的方法,pythonurllib2
- python通过get,post方式发送http请求和接收http响应的方法,
- python统计文本字符串里单词出现频率的方法,
- Python OS模块常用函数说明,pythonos模块函数
- Python标准库之Sys模块使用详解,python使用详解
- 详解Python中的各种函数的使用,详解python函数
- Python中关于使用模块的基础知识,python基础知识
评论关闭