2024-09-01
Linux运维
00

python 代码:

python
import os import shutil import traceback def delete_folder(path): if os.path.exists(path): print(f"删除文件夹: {path}") shutil.rmtree(path) print("删除完成") def delete_file(path): if os.path.exists(path): print(f"删除文件: {path}") os.remove(path) print("删除完成") def clean_project(src_root): for root, dirs, files in os.walk(src_root): try: for filename in files: apath = os.path.join(root, filename) # 文件大于10M就打印 if os.path.getsize(apath) > 10 * 1024 * 1024: print(f"文件: {apath} 大小: {os.path.getsize(apath) / (1024 ** 2):.2f}M") # 删除.gradle文件夹 if ".gradle" in dirs: dir_path = os.path.join(root, ".gradle") dir_size = shutil.disk_usage(dir_path).used / (1024 ** 2) if dir_size > 5: delete_folder(dir_path) else: print(f"文件夹: {dir_path} 大小: {dir_size:.2f}M") # 删除.idea文件夹 if ".idea" in dirs: delete_folder(os.path.join(root, ".idea")) # 删除.iml文件和local.properties文件 for file in files: file_path = os.path.join(root, file) if file.endswith(".iml") or file == "local.properties": delete_file(file_path) # 删除build文件夹 if "build" in dirs: delete_folder(os.path.join(root, "build")) # 删除libs文件夹 if "libs" in dirs: delete_folder(os.path.join(root, "libs")) # 删除androidTest文件夹 if "androidTest" in dirs: delete_folder(os.path.join(root, "androidTest")) # 删除test文件夹 if "test" in dirs: delete_folder(os.path.join(root, "test")) except: traceback.print_exc() if __name__ == "__main__": src_root = r"F:\workcode\android_project" clean_project(src_root)
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Dong

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!