python读取目录下指定字符的文件_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()

你可能感兴趣的:(python读取目录下指定字符的文件_python检索目录下所有文件中包含指定字符串的文件...)