import os
from os import path
import datetime
def getAllFile(rootPath):
fileList = []
files=os.listdir(rootPath) #获取文件列表
for fileName in files:
fullpath=path.join(rootPath,fileName)
if(path.isdir(fullpath)):#如果是文件夹 递归出所有的文件 添加到数组中
getAllFile(fileList,fullpath)
else:
if str(datetime.date.today() - datetime.timedelta(days=1)) in fullpath or str(datetime.date.today() - datetime.timedelta(days=1)).replace('-','') in fullpath: #按需过滤自己想要识别的文件
fileList.append(fullpath)
else:
pass
return fileList
# def readFileLine(lineCount,fileArray):
# length=len(fileArray)
# for i in range(lineCount,length):
# count = len(open(fileArray[i],'rb').readlines())
# lineCount=lineCount+count
# return lineCount
def readFileLine(lineCount,fileArray):
length=len(fileArray)
for i in range(lineCount,length):
count = os.popen('cat {}|wc -l '.format(fileArray[i])).read()
lineCount=lineCount+count
return lineCount
def run(p):
for i in os.listdir(p):
print(i,readFileLine(0,getAllFile(os.path.join(p,i))))
p=r'C:\Users\mzj\Desktop\dp'
run(p)
# print( datetime.date.today() - datetime.timedelta(days=1))