当前位置: 移动技术网 > IT编程>脚本编程>Python > 用Python遍历C盘dll文件的方法

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

2018年06月22日  | 移动技术网IT编程  | 我要评论

帝赐尔,新概念英语视频教程,贺家铁的父国强

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

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>


如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网