查找包含多个字符的文件,包含多个字符,查找指定目录和文件类型下


查找指定目录和文件类型下, 包含多个字符的文件, 自己用来查下代码和文本

python getfile.py 路径 文件类型 关键字 可以多个关键字中间有空格隔开

例:python getfile.py d:\java .java 线路单 判断 条件

#encoding:gb2312import os, sysfind_text = sys.argvdiro = find_text[1]filetype = find_text[2]print '\\n搜索目录 %s' % diroprint '搜索文件类型 %s' % filetypeprint '关键字: ',' '.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://byrx.net

评论关闭