源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-12-01 18:31 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:用Python遍历C盘dll文件的方法
python 的[url=http://docs.python.org/library/fnmatch.html]fnmatch [/url]还真是省心,相比于 java 中的[url=http://download.oracle.com/javase/1.4.2/docs/api/java/io/FilenameFilter.html]FilenameFilter [/url],真是好太多了,你完成不需要去实现什么接口。 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>

  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部