PCM_Report/cleanup_old_files.py

67 lines
1.9 KiB
Python

"""
清理旧的配置文件,只保留固定文件名的文件
"""
import os
from pathlib import Path
def cleanup_old_files():
"""清理旧的配置文件"""
base_dir = Path(__file__).resolve().parent
config_root = base_dir / "configs"
if not config_root.exists():
print("configs/ 目录不存在")
return
print("开始清理旧文件...")
print("="*50)
# 要删除的旧文件名
old_files = ["default.json", "template-001.docx"]
for category_dir in config_root.iterdir():
if not category_dir.is_dir():
continue
print(f"\n检查分类: {category_dir.name}")
for old_file in old_files:
old_path = category_dir / old_file
if old_path.exists():
try:
old_path.unlink()
print(f" ✓ 已删除: {old_file}")
except Exception as e:
print(f" ✗ 删除失败: {old_file} - {e}")
else:
print(f" - 不存在: {old_file}")
# 检查新文件是否存在
config_json = category_dir / "config.json"
template_docx = category_dir / "template.docx"
if config_json.exists():
print(f" ✓ config.json 存在")
else:
print(f" ⚠ config.json 不存在")
if template_docx.exists():
print(f" ✓ template.docx 存在")
else:
print(f" ⚠ template.docx 不存在")
print("\n" + "="*50)
print("清理完成!")
print("\n当前文件结构应该是:")
print("configs/")
print(" ├── 600泵/")
print(" │ ├── config.json")
print(" │ └── template.docx")
print(" └── 1000泵/")
print(" ├── config.json")
print(" └── template.docx")
if __name__ == "__main__":
cleanup_old_files()