MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / clean_files

Method clean_files

script/btcli.py:1032–1070  ·  view source on GitHub ↗

清理文件列表 返回: (成功数量, 失败数量)

(self, files: List[str], show_progress: bool = True)

Source from the content-addressed store, hash-verified

1030 print()
1031
1032 def clean_files(self, files: List[str], show_progress: bool = True) -> Tuple[int, int]:
1033 """
1034 清理文件列表
1035 返回: (成功数量, 失败数量)
1036 """
1037 success = 0
1038 failed = 0
1039 total = len(files)
1040
1041 for idx, filepath in enumerate(files, 1):
1042 if show_progress:
1043 percentage = (idx / total) * 100
1044 bar_length = 40
1045 filled_length = int(bar_length * idx // total)
1046 bar = '█' * filled_length + '-' * (bar_length - filled_length)
1047
1048 print(f" 进度: |{bar}| {percentage:.1f}% ({idx}/{total})", end='\r')
1049
1050 try:
1051 #.log后缀为清空内容
1052 if os.path.isfile(filepath):
1053 if filepath.endswith('.log'):
1054 with open(filepath, 'w') as f:
1055 pass
1056 success += 1
1057 else:
1058 os.remove(filepath)
1059 success += 1
1060 #非.log后缀为删除文件
1061 elif os.path.isdir(filepath):
1062 shutil.rmtree(filepath)
1063 success += 1
1064 except (OSError, PermissionError) as e:
1065 failed += 1
1066
1067 if show_progress:
1068 print() #
1069
1070 return success, failed
1071
1072 def clean_category(self, category_name: str, rule_keys: List[str] = None):
1073 """清理指定分类"""

Callers 3

clean_categoryMethod · 0.95
clean_by_numbersMethod · 0.95
clean_allMethod · 0.95

Calls 2

openFunction · 0.85
removeMethod · 0.45

Tested by

no test coverage detected