| import os |
| import re |
|
|
| DATA_DIRS = [ |
| r"backend\data\thông tin thuốc nội bộ", |
| r"backend\data\cảnh giác dược" |
| ] |
|
|
| |
| |
| pattern1 = re.compile(r"__[a-f0-9]{8,}\.md$", re.IGNORECASE) |
|
|
| |
| pattern2 = re.compile(r" [a-f0-9]{32}.*\.(md|csv)$", re.IGNORECASE) |
|
|
| def cleanup_folder(folder_path): |
| if not os.path.exists(folder_path): |
| print(f"Không tìm thấy thư mục: {folder_path}") |
| return |
|
|
| count = 0 |
| size_saved = 0 |
| for file_name in os.listdir(folder_path): |
| if pattern1.search(file_name) or pattern2.search(file_name): |
| file_path = os.path.join(folder_path, file_name) |
| try: |
| size = os.path.getsize(file_path) |
| os.remove(file_path) |
| print(f"Đã xoá: {file_name}") |
| count += 1 |
| size_saved += size |
| except Exception as e: |
| print(f"Không thể xoá {file_name}: {e}") |
| |
| print(f"--- Dọn dẹp xong {folder_path} ---") |
| print(f"Xoá tổng cộng: {count} tập tin rác.") |
| print(f"Tiết kiệm được: {size_saved / 1024 / 1024:.2f} MB\n") |
|
|
| if __name__ == "__main__": |
| print("BẮT ĐẦU DỌN DẸP...\n") |
| base_dir = os.path.dirname(os.path.abspath(__file__)) |
| for d in DATA_DIRS: |
| folder_path = os.path.join(base_dir, d) |
| cleanup_folder(folder_path) |
| print("HOÀN TẤT DỌN DẸP!") |
|
|