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

作者:goldensun 时间:2023-04-27 20:15:27 

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
0
投稿

猜你喜欢

  • Mysql 本地计算机无法启动 mysql 服务 错误 1067:进程意外终止。

    2024-01-27 19:30:56
  • js捕捉窗口的关闭与刷新

    2008-10-08 10:20:00
  • 区别JavaScript函数声明与变量声明

    2024-04-18 09:34:42
  • python字符串,元组,列表,字典互转代码实例详解

    2022-03-01 22:51:55
  • SQLServer 2005 实现数据库同步备份 过程-结果-分析

    2012-07-11 15:56:55
  • 在Python编程过程中用单元测试法调试代码的介绍

    2023-12-10 02:16:46
  • python optparse模块使用实例

    2021-02-03 22:01:36
  • Python Selenium 之数据驱动测试的实现

    2021-12-16 22:45:27
  • Vue3 通过作用域插槽实现树形菜单嵌套组件

    2024-05-28 15:42:28
  • mac os10.12安装mysql5.7.18教程

    2024-01-19 14:08:27
  • PYTHON正则表达式 re模块使用说明

    2021-11-25 15:06:50
  • python3.7调试的实例方法

    2022-09-22 17:16:24
  • Javascript typeof 用法

    2013-10-20 20:49:40
  • Django中使用session保持用户登陆连接的例子

    2021-08-29 03:27:30
  • jasypt 集成SpringBoot 数据库密码加密操作

    2024-01-26 03:34:48
  • 纯ASP(VBscript)写的全球IP地址搜索程序

    2007-09-27 13:28:00
  • Tensorflow卷积实现原理+手写python代码实现卷积教程

    2021-12-21 20:12:52
  • vscode调试container中的程序的方法步骤

    2022-03-06 14:20:25
  • Python arrow 更好的日期时间模块

    2022-02-08 14:06:15
  • Python实现爬取网页中动态加载的数据

    2021-08-11 18:35:27
  • asp之家 网络编程 m.aspxhome.com