delReport.py
1.07 KB
# -*- coding: utf-8 -*-
# @Time : 2021/7/19 14:35
# @Author : Ljq
# @File : delectReport.py
# @Software: PyCharm
"""
用于删除多余的报告文件
"""
import os,sys
def path_route(path):
if "report" not in os.listdir(path):
return path_route(os.path.abspath(os.path.join(path, "../")))
else:
return path
def delReport(path,delNum=5):
report_path = path_route(path) + "/report/"
file_list = os.listdir(report_path)
print("befor sort file_lis --- ", file_list)
if len(file_list) > delNum:
file_list.sort(key=lambda file_name: os.path.getmtime(report_path + file_name))
print("after sort file_lis --- ", file_list)
file_list = file_list[:0-delNum]
# print("if file_lis --- ",file_list)
for i in file_list:
if os.path.isfile(report_path + i) and ".html" in i:
os.remove(report_path + i)
print(f"删除报告 {i} 成功")
# 文件已删除
print("多余的报告文件已删除")
else:
print("没有需要删除的文件")