亲宝软件园·资讯

展开

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

人气:0
想了解用Python遍历C盘dll文件的方法的相关内容吗,在本文为您仔细讲解Python遍历C盘dll文件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Python,下面大家一起来学习吧。

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>


加载全部内容

相关教程
猜你喜欢
用户评论