- #encoding:gb2312
- import os, sys
- find_text = sys.argv
- diro = find_text[1]
- filetype = find_text[2]
- print '\\n搜索目录 %s' % diro
- print '搜索文件类型 %s' % filetype
- print '关键字: ',' '.join(find_text[3:])
- print '\\n\\n查询到包含关键字文件:\\n'
- for root, subdirs, filename in os.walk(diro):
- for i in filename :
- if (i.endswith(filetype)):
- infile = open(root+'\\\\'+i, 'r')
- content = infile.read().lower()
- for j in find_text[3:]:
- if j in content:
- sts = True
- else:
- sts = False
- break
- if sts == True:
- print root+'\\\\'+i
- #该片段来自于http://www.codesnippet.cn/detail/101220137893.html
来源: http://www.codesnippet.cn/detail/101220137893.html