delReport.py 984 Bytes
# -*- 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):
    project_path = path_route(path)
    file_list = os.listdir(project_path + "/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(project_path + "/report/" + i) and ".html" in i:
                os.remove(project_path + "/report/" + i)
                print(f"删除报告    {i}     成功")
        # 文件已删除
        print("多余的报告文件已删除")
    else:
        print("没有需要删除的文件")