设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 34530|回复: 0
打印 上一主题 下一主题

【每日一坑 4】 查找文件

[复制链接]

0

主题

0

好友

16

积分

新手上路

Rank: 1

楼主
发表于 2017-10-6 12:01:57 |显示全部楼层
  1. import os
  2. import fnmatch

  3. def iterfindfiles(path,fnexp):
  4.     for root, dirs, files in os.walk(path):
  5.         for filename in fnmatch.filter(files,fnexp):
  6.             yield os.path.join(root, filename)

  7. for filename in iterfindfiles(r"G:/Python","*.txt"):
  8.     print filename
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-18 18:37 , Processed in 0.025100 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部