linux下grep命令就可以检索 配合其他遍历命令可以实现检索目录下文件中包含指定字符串的文件
windows下不知有没有这类工具,自己写个小工具
- import os
- import re
-
- # list files
- def listFiles(dirPath):
- fileList = [];
- for root, dirs, files in os.walk(dirPath):
- for fileObj in files:
- fileList.append(os.path.join(root,fileObj))
- return fileList
-
- def findString(filePath, regex):
- fileObj = open(filePath, 'r')
- for eachLine in fileObj:
- if re.search(regex, eachLine, re.I):
- print fileObj
- break
-
- def main():
- fileDir = "e:"+os.sep+"Package"
- regex = ur'FUNC_SYS_ADD_ACCDETAIL'
- fileList = listFiles(fileDir)
- for fileObj in fileList:
- findString(fileObj, regex)
- os.system("pause")
-
- if __name__ == '__main__':
- main()
|