python获取指定路径下所有指定后缀文件的方法
2015-07-29 20:30
801 查看
<p style="margin-top: 0px; margin-bottom: 0px; padding-top: 5px; padding-bottom: 5px; font-size: 14px; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px;">本文实例讲述了python获取指定路径下所有指定后缀文件的方法。分享给大家供大家参考。具体实现方法如下:</p><div> </div>
# 获取指定路径下所有指定后缀的文件 # 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学习——Numpy(1)
- Python 选择排序
- 3.Python基础 序列sequence
- Python re 正则模块
- python基础教程总结15——6 CGI远程编辑
- openCV—Python(6)—— 图像算数与逻辑运算
- python os.walk和os.path.walk
- 用python免登錄把人人網某個相冊的全部照片下載下來
- [python]学习笔记3-字符串内建函数2
- Python 用 os.walk 遍历目录
- python练习题(二)
- python模拟新浪微博登陆功能(新浪微博爬虫)
- python显示灰度图
- Python yield 使用浅析
- Python安装
- python设计模式之Borg模式
- python设计模式之Builder模式
- python设计模式之状态模式
- Python 拷贝对象(深拷贝deepcopy与浅拷贝copy)
- python设计模式之抽象工厂模式