手机
当前位置:查字典教程网 >脚本专栏 >python >用Python遍历C盘dll文件的方法
用Python遍历C盘dll文件的方法
摘要:python的fnmatch还真是省心,相比于java中的FilenameFilter,真是好太多了,你完成不需要去实现什么接口。fnmat...

python 的fnmatch 还真是省心,相比于 java 中的FilenameFilter ,真是好太多了,你完成不需要去实现什么接口。

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中使用urllib2伪造HTTP报头的2个方法

python复制文件代码实现

python两种遍历字典(dict)的方法比较

使用python装饰器验证配置文件示例

Python 返回汉字的汉语拼音

Python文件夹与文件的操作实现代码

python装饰器使用方法实例

盘点提高 Python 代码效率的方法

python回调函数的使用方法

Python open读写文件实现脚本

精品推荐
分类导航