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

yipeiwu_com6年前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>


相关文章

Python实现新浪博客备份的方法

本文实例讲述了Python实现新浪博客备份的方法。分享给大家供大家参考,具体如下: Python2.7.2版本实现,推荐在IDE中运行。 # -*- coding:UTF-8 -*-...

Python语法分析之字符串格式化

前序 There should be one - and preferably only one - obvious way to do it. ———— the Zen of Pyt...

Windows和Linux下使用Python访问SqlServer的方法介绍

经常用Python写demo来验证方案的可行性,最近遇到了Python访问SqlServer的问题,这里总结下。 一、Windows下配置Python访问Sqlserver 环境:Win...

画pytorch模型图,以及参数计算的方法

画pytorch模型图,以及参数计算的方法

刚入pytorch的坑,代码还没看太懂。之前用keras用习惯了,第一次使用pytorch还有些不适应,希望广大老司机多多指教。 首先说说,我们如何可视化模型。在keras中就一句话,k...

Python实现豆瓣图片下载的方法

本文实例讲述了Python实现豆瓣图片下载的方法。分享给大家供大家参考。具体分析如下: 1 用 tk 封装一下 2 用户可以自己输入图片url download_douban_alb...