您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

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

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   这篇文章主要介绍了用Python遍历C盘dll文件的方法,用fnmatch模块实现起来非常简单,需要的朋友可以参考下

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

  fnmatch 配合 os.walk() 或者 os.listdir() ,你能做的事太多了,而且用起来相当 easy。

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 # 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>