shutil 结合 os 删除所有文件及文件夹
import shutil import os def del_file(filepath): try: del_list = os.listdir(filepath) except Exception as e: return for f in del_list: file_path = os.path.join(filepath, f) if os.path.isfile(file_path): os.remove(file_path) elif os.path.isdir(file_path): shutil.rmtree(file_path) os.removedirs(filepath)
本文来自博客园,作者:CodeYaSuo,转载请注明原文链接:https://www.cnblogs.com/hany-postq473111315/p/15895344.html