设为首页收藏本站

Crossin的编程教室

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

【每日一坑 6】 查找文件内容

[复制链接]

1

主题

0

好友

207

积分

中级会员

Rank: 3Rank: 3

楼主
发表于 2016-1-16 14:37:10 |显示全部楼层

回帖奖励 +5

  1. import re
  2. import os

  3. def check(dir,text):
  4.   for i in os.listdir(dir):
  5.     if os.path.isdir(i): check(dir + "/" + i,text)
  6.     if re.search(r'.*\.txt',i):
  7.       file = open(dir + "/" + i,encoding="utf8").read()
  8.       print(str(i) + "\n" if re.search(text,file) else "",end="")

  9. check(os.getcwd(),"hello world")
复制代码
回复

使用道具 举报

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

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

GMT+8, 2024-5-3 03:54 , Processed in 0.032856 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部