12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import os
- import shutil
- # 你的字符串列表,包含文件夹的路径
- folder_list = ["AnnotationImportExportTest", "AnnotationTest", "BackgroundTest", "BatesTest", "BookmarkTest",
- "DigitalSignatureTest", "DocumentCompareTest", "DocumentInfoTest",
- "EncryptTest", "FlattenTest", "HeaderFooterTest",
- "ImageExtractTest", "InteractiveFormsTest", "OutlineTest",
- "PDFATest", "PDFPageTest", "PDFRedactTest",
- "PDFToImageTest", "TextExtractTest", "TextSearchTest", "WatermarkTest"]
- def delete_bin_obj_folders(folder_path):
- # 检查文件夹是否存在
- if not os.path.exists(folder_path):
- print(f"文件夹 '{folder_path}' 不存在.")
- return
- # 遍历文件夹中的文件和子文件夹
- for item in os.listdir(folder_path):
- item_path = os.path.join(folder_path, item)
- # 如果是子文件夹,递归调用删除函数
- if os.path.isdir(item_path):
- delete_bin_obj_folders(item_path)
- # 删除bin和obj目录
- if "bin" in os.listdir(folder_path):
- shutil.rmtree(os.path.join(folder_path, "bin"))
- print(f"已删除 '{os.path.join(folder_path, 'bin')}' 目录.")
- if "obj" in os.listdir(folder_path):
- shutil.rmtree(os.path.join(folder_path, "obj"))
- print(f"已删除 '{os.path.join(folder_path, 'obj')}' 目录.")
- def do_delete_bin_obj_folders():
- # 遍历文件夹列表并执行删除操作
- for folder_path in folder_list:
- delete_bin_obj_folders(folder_path)
- def delete_extra_CS_folder_in_CS_folders(folder_path):
- cs_folder_path = os.path.join(folder_path, "CS")
- # 检查CS文件夹是否存在
- if os.path.exists(cs_folder_path) and os.path.isdir(cs_folder_path):
- cs_contents = os.listdir(cs_folder_path)
- # 如果CS文件夹中包含名为"CS"的子文件夹,则删除多余的"CS"子文件夹
- if "CS" in cs_contents:
- shutil.rmtree(os.path.join(cs_folder_path, "CS"))
- print(f"已删除 '{os.path.join(cs_folder_path, 'CS')}' 目录.")
- def do_delete_extra_CS_folder_in_CS_folders():
- # 遍历文件夹列表并执行删除操作
- for folder_path in folder_list:
- delete_extra_CS_folder_in_CS_folders(folder_path)
- # 递归遍历文件夹中的文件和子文件夹
- def show_dir_contents(folder_path):
- # 检查文件夹是否存在
- if not os.path.exists(folder_path):
- print(f"文件夹 '{folder_path}' 不存在.")
- return
- # 遍历文件夹中的文件和子文件夹
- for item in os.listdir(folder_path):
- item_path = os.path.join(folder_path, item)
- # 如果是子文件夹,递归调用遍历函数
- if os.path.isdir(item_path):
- show_dir_contents(item_path)
- else:
- print(item_path)
- def do_show_dir_contents():
- # 遍历文件夹列表并执行遍历操作
- for folder_path in folder_list:
- show_dir_contents(folder_path)
- def main():
- do_delete_bin_obj_folders()
- do_delete_extra_CS_folder_in_CS_folders()
- print("清理完成.")
- do_show_dir_contents()
- if __name__ == "__main__":
- main()
|