cleanup_unused_files.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 清理Excel目录中的无用文件
  5. 保留核心配置工具和配置表文件
  6. """
  7. import os
  8. from pathlib import Path
  9. def cleanup_unused_files():
  10. """清理无用的文件"""
  11. excel_dir = Path(__file__).parent
  12. # 需要保留的核心文件
  13. keep_files = {
  14. # 核心配置工具
  15. 'config_manager.py',
  16. 'json_to_excel.py',
  17. 'verify_excel.py',
  18. 'sync_json_to_excel.py',
  19. 'verify_sync.py',
  20. # 启动脚本
  21. '启动配置工具.bat',
  22. '生成技能配置表.bat',
  23. # 配置表文件
  24. '敌人配置表.xlsx',
  25. '敌人配置表.backup.xlsx',
  26. '技能配置表.xlsx',
  27. '局外技能配置表.xlsx',
  28. 'BallController标准配置表.xlsx',
  29. # 说明文档
  30. '敌人配置表说明.md',
  31. '多配置表管理工具使用说明.md',
  32. '配置工具使用说明.md',
  33. '部署使用说明.md',
  34. '更新说明.md',
  35. # 依赖文件
  36. 'requirements.txt'
  37. }
  38. # 需要保留的目录
  39. keep_dirs = {
  40. '关卡配置',
  41. '方块武器配置',
  42. '__pycache__'
  43. }
  44. # 可以删除的临时和测试文件
  45. files_to_delete = []
  46. for item in excel_dir.iterdir():
  47. if item.is_file():
  48. # 跳过.meta文件,它们是Cocos Creator需要的
  49. if item.suffix == '.meta':
  50. continue
  51. if item.name not in keep_files:
  52. # 检查是否是临时或测试文件
  53. if (item.name.startswith('test_') or
  54. item.name.startswith('analyze_') or
  55. item.name.startswith('compare_') or
  56. item.name.startswith('final_') or
  57. item.name.startswith('fix_') or
  58. item.name.startswith('optimize_') or
  59. item.name.startswith('redesign_') or
  60. item.name.startswith('remove_') or
  61. item.name.startswith('update_') or
  62. item.name.startswith('verify_') and item.name != 'verify_excel.py' and item.name != 'verify_sync.py' or
  63. item.name.startswith('create_') or
  64. item.name.startswith('generate_') or
  65. item.name.startswith('import_') or
  66. item.name.startswith('skill_config_') or
  67. item.suffix == '.csv' or
  68. item.suffix == '.json' and 'result' in item.name):
  69. files_to_delete.append(item)
  70. elif item.is_dir() and item.name not in keep_dirs:
  71. # 暂时不删除目录,只列出
  72. print(f"目录 {item.name} 可能需要手动检查")
  73. if not files_to_delete:
  74. print("没有找到需要删除的无用文件")
  75. return
  76. print(f"找到 {len(files_to_delete)} 个可以删除的文件:")
  77. for file_path in files_to_delete:
  78. print(f" - {file_path.name}")
  79. # 确认删除
  80. response = input("\n确认删除这些文件吗?(y/N): ")
  81. if response.lower() in ['y', 'yes']:
  82. deleted_count = 0
  83. for file_path in files_to_delete:
  84. try:
  85. file_path.unlink()
  86. print(f"已删除: {file_path.name}")
  87. deleted_count += 1
  88. except Exception as e:
  89. print(f"删除失败 {file_path.name}: {e}")
  90. print(f"\n清理完成!成功删除 {deleted_count} 个文件")
  91. else:
  92. print("取消删除操作")
  93. if __name__ == '__main__':
  94. cleanup_unused_files()