</pre><pre name="code" class="python">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()
转自:http://blog.csdn.net/authorzhh/article/details/8933758