Commit 6cac0f7d1f7c1c145f1c6148e3dcbe7e36b6ceb0
1 parent
6b798ce0
更新
Showing
1 changed file
with
6 additions
and
4 deletions
commons/scripts/delReport.py
... | ... | @@ -18,15 +18,17 @@ def path_route(path): |
18 | 18 | return path |
19 | 19 | |
20 | 20 | def delReport(path,delNum=5): |
21 | - project_path = path_route(path) | |
22 | - file_list = os.listdir(project_path + "/report/") | |
21 | + report_path = path_route(path) + "/report/" | |
22 | + file_list = os.listdir(report_path) | |
23 | 23 | print("delReport file_lis --- ", file_list) |
24 | 24 | if len(file_list) > delNum: |
25 | + file_list.sort(key=lambda file_name: os.path.getmtime(report_path + "\\" + file_name)) | |
26 | + print(file_list) | |
25 | 27 | file_list = file_list[:0-delNum] |
26 | 28 | # print("if file_lis --- ",file_list) |
27 | 29 | for i in file_list: |
28 | - if os.path.isfile(project_path + "/report/" + i) and ".html" in i: | |
29 | - os.remove(project_path + "/report/" + i) | |
30 | + if os.path.isfile(report_path + i) and ".html" in i: | |
31 | + os.remove(report_path + i) | |
30 | 32 | print(f"删除报告 {i} 成功") |
31 | 33 | # 文件已删除 |
32 | 34 | print("多余的报告文件已删除") | ... | ... |