筛选最新生成的报告——sort

筛选出最新报告发送,返回报告路径

import os
def filePath(path):
return os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))),path)
#所有报告都放在report下面
def reportPath():
#筛选出最新生成的报告
reportPath=filePath('report')
listDir=os.listdir(reportPath)
listDir.sort(key=lambda fn:os.path.getmtime(reportPath+"\\"+fn) if not os.path.isdir(reportPath+'\\'+fn) else 0)
file_new=os.path.join(reportPath,listDir[-1])
return file_new
posted @ 2018-05-12 14:08  残~枫~  阅读(126)  评论(0编辑  收藏  举报