os模块清空而不删除文件夹
import shutil import os
# UPLOAD_PATH = "/data/www/static/uploads"
if os.path.exists(UPLOAD_PATH): for i in os.listdir(UPLOAD_PATH): path_file = os.path.join(UPLOAD_PATH, i) if os.path.isfile(path_file): os.remove(path_file) elif os.path.isdir(path_file): shutil.rmtree(path_file) else: pass print("OK delete uploads datasets") else: print("文件不存在 cant find dir and file")