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