import os
import shutil
def delete_files(src_dir):
for file in os.listdir(del_dirs):
if os.path.isdir(os.path.join(del_dirs, file)):
shutil.rmtree(os.path.join(del_dirs, file))
else:
os.remove(os.path.join(del_dirs, file))
return
if __name__ == '__main__':
del_dirs = ''
delete_files(src_dir=del_dirs)
判断一下,如果是文件,os.remove, 如果是文件夹,shutil.rmtree