| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- 清理Excel目录中的无用文件
- 保留核心配置工具和配置表文件
- """
- import os
- from pathlib import Path
- def cleanup_unused_files():
- """清理无用的文件"""
- excel_dir = Path(__file__).parent
-
- # 需要保留的核心文件
- keep_files = {
- # 核心配置工具
- 'config_manager.py',
- 'json_to_excel.py',
- 'verify_excel.py',
- 'sync_json_to_excel.py',
- 'verify_sync.py',
-
- # 启动脚本
- '启动配置工具.bat',
- '生成技能配置表.bat',
-
- # 配置表文件
- '敌人配置表.xlsx',
- '敌人配置表.backup.xlsx',
- '技能配置表.xlsx',
- '局外技能配置表.xlsx',
- 'BallController标准配置表.xlsx',
-
- # 说明文档
- '敌人配置表说明.md',
- '多配置表管理工具使用说明.md',
- '配置工具使用说明.md',
- '部署使用说明.md',
- '更新说明.md',
-
- # 依赖文件
- 'requirements.txt'
- }
-
- # 需要保留的目录
- keep_dirs = {
- '关卡配置',
- '方块武器配置',
- '__pycache__'
- }
-
- # 可以删除的临时和测试文件
- files_to_delete = []
-
- for item in excel_dir.iterdir():
- if item.is_file():
- # 跳过.meta文件,它们是Cocos Creator需要的
- if item.suffix == '.meta':
- continue
-
- if item.name not in keep_files:
- # 检查是否是临时或测试文件
- if (item.name.startswith('test_') or
- item.name.startswith('analyze_') or
- item.name.startswith('compare_') or
- item.name.startswith('final_') or
- item.name.startswith('fix_') or
- item.name.startswith('optimize_') or
- item.name.startswith('redesign_') or
- item.name.startswith('remove_') or
- item.name.startswith('update_') or
- item.name.startswith('verify_') and item.name != 'verify_excel.py' and item.name != 'verify_sync.py' or
- item.name.startswith('create_') or
- item.name.startswith('generate_') or
- item.name.startswith('import_') or
- item.name.startswith('skill_config_') or
- item.suffix == '.csv' or
- item.suffix == '.json' and 'result' in item.name):
- files_to_delete.append(item)
- elif item.is_dir() and item.name not in keep_dirs:
- # 暂时不删除目录,只列出
- print(f"目录 {item.name} 可能需要手动检查")
-
- if not files_to_delete:
- print("没有找到需要删除的无用文件")
- return
-
- print(f"找到 {len(files_to_delete)} 个可以删除的文件:")
- for file_path in files_to_delete:
- print(f" - {file_path.name}")
-
- # 确认删除
- response = input("\n确认删除这些文件吗?(y/N): ")
- if response.lower() in ['y', 'yes']:
- deleted_count = 0
- for file_path in files_to_delete:
- try:
- file_path.unlink()
- print(f"已删除: {file_path.name}")
- deleted_count += 1
- except Exception as e:
- print(f"删除失败 {file_path.name}: {e}")
-
- print(f"\n清理完成!成功删除 {deleted_count} 个文件")
- else:
- print("取消删除操作")
- if __name__ == '__main__':
- cleanup_unused_files()
|