clean_test.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import os
  2. import shutil
  3. # 你的字符串列表,包含文件夹的路径
  4. folder_list = ["AnnotationImportExportTest", "AnnotationTest", "BackgroundTest", "BatesTest", "BookmarkTest",
  5. "DigitalSignatureTest", "DocumentCompareTest", "DocumentInfoTest",
  6. "EncryptTest", "FlattenTest", "HeaderFooterTest",
  7. "ImageExtractTest", "InteractiveFormsTest", "OutlineTest",
  8. "PDFATest", "PDFPageTest", "PDFRedactTest",
  9. "PDFToImageTest", "TextExtractTest", "TextSearchTest", "WatermarkTest"]
  10. def delete_bin_obj_folders(folder_path):
  11. # 检查文件夹是否存在
  12. if not os.path.exists(folder_path):
  13. print(f"文件夹 '{folder_path}' 不存在.")
  14. return
  15. # 遍历文件夹中的文件和子文件夹
  16. for item in os.listdir(folder_path):
  17. item_path = os.path.join(folder_path, item)
  18. # 如果是子文件夹,递归调用删除函数
  19. if os.path.isdir(item_path):
  20. delete_bin_obj_folders(item_path)
  21. # 删除bin和obj目录
  22. if "bin" in os.listdir(folder_path):
  23. shutil.rmtree(os.path.join(folder_path, "bin"))
  24. print(f"已删除 '{os.path.join(folder_path, 'bin')}' 目录.")
  25. if "obj" in os.listdir(folder_path):
  26. shutil.rmtree(os.path.join(folder_path, "obj"))
  27. print(f"已删除 '{os.path.join(folder_path, 'obj')}' 目录.")
  28. def do_delete_bin_obj_folders():
  29. # 遍历文件夹列表并执行删除操作
  30. for folder_path in folder_list:
  31. delete_bin_obj_folders(folder_path)
  32. def delete_extra_CS_folder_in_CS_folders(folder_path):
  33. cs_folder_path = os.path.join(folder_path, "CS")
  34. # 检查CS文件夹是否存在
  35. if os.path.exists(cs_folder_path) and os.path.isdir(cs_folder_path):
  36. cs_contents = os.listdir(cs_folder_path)
  37. # 如果CS文件夹中包含名为"CS"的子文件夹,则删除多余的"CS"子文件夹
  38. if "CS" in cs_contents:
  39. shutil.rmtree(os.path.join(cs_folder_path, "CS"))
  40. print(f"已删除 '{os.path.join(cs_folder_path, 'CS')}' 目录.")
  41. def do_delete_extra_CS_folder_in_CS_folders():
  42. # 遍历文件夹列表并执行删除操作
  43. for folder_path in folder_list:
  44. delete_extra_CS_folder_in_CS_folders(folder_path)
  45. # 递归遍历文件夹中的文件和子文件夹
  46. def show_dir_contents(folder_path):
  47. # 检查文件夹是否存在
  48. if not os.path.exists(folder_path):
  49. print(f"文件夹 '{folder_path}' 不存在.")
  50. return
  51. # 遍历文件夹中的文件和子文件夹
  52. for item in os.listdir(folder_path):
  53. item_path = os.path.join(folder_path, item)
  54. # 如果是子文件夹,递归调用遍历函数
  55. if os.path.isdir(item_path):
  56. show_dir_contents(item_path)
  57. else:
  58. print(item_path)
  59. def do_show_dir_contents():
  60. # 遍历文件夹列表并执行遍历操作
  61. for folder_path in folder_list:
  62. show_dir_contents(folder_path)
  63. def main():
  64. do_delete_bin_obj_folders()
  65. do_delete_extra_CS_folder_in_CS_folders()
  66. print("清理完成.")
  67. do_show_dir_contents()
  68. if __name__ == "__main__":
  69. main()