1.os.walk
import os for root, dirs, files in os.walk(top, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) ---------------------
2.remove # 删除文件
3.rmdir # 删除文件夹
4.removedirs(path) # 递归删除文件夹