用Python遍历C盘dll文件的方法
2015-05-06 00:00
429 查看
python 的fnmatch 还真是省心,相比于 java 中的FilenameFilter ,真是好太多了,你完成不需要去实现什么接口。
fnmatch 配合 os.walk() 或者 os.listdir() ,你能做的事太多了,而且用起来相当 easy。
fnmatch 配合 os.walk() 或者 os.listdir() ,你能做的事太多了,而且用起来相当 easy。
# coding: utf-8 """ 遍历C盘下的所有dll文件 """ import os import fnmatch def main(): f = open('dll_list.txt', 'w') for root, dirs, files in os.walk('c:\\'): for name in files: if fnmatch.fnmatch(name, '*.dll'): f.write(os.path.join(root, name)) f.write('\n') f.close() print 'done...' if __name__=='__main__': main()</pre>
相关文章推荐
- 用Python遍历C盘dll文件的方法
- Python遍历zip文件输出名称时出现乱码问题的解决方法
- Python遍历指定文件及文件夹的方法
- Python遍历指定文件及文件夹的方法
- Python遍历文件夹和读写文件的方法
- python中遍历文件的3个方法
- python中遍历文件的3个方法
- Python遍历目录中的所有文件的方法
- Python遍历目录中的所有文件的方法
- 【Python】三种遍历文件目录的方法
- python中遍历文件的3个方法
- python中遍历文件的3个方法
- Python遍历文件夹和读写文件的方法
- Python遍历文件夹和读写文件的实现方法
- Python遍历文件夹和读写文件的方法
- Python文件遍历的三种方法
- python指定文件目录遍历方法
- python 遍历文件(夹) 的os.walk方法
- Python遍历目录文件的两种方法
- python遍历文件夹——两种遍历本地文件记录文件夹个数、文件数及文件大小的方法