Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > Python与其他语言

用Python遍历C盘dll文件的方法

来源:中文源码网    浏览:163 次    日期:2024-05-18 08:39:48
【下载文档:  用Python遍历C盘dll文件的方法.txt 】


用Python遍历C盘dll文件的方法
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()

相关内容