37,720
社区成员
发帖
与我相关
我的任务
分享
# 删除文件
s_dir = 'E:/xxx'
try:
# 使用os模块删除
os.remove(s_dir)
except Exception as error:
# 使用windows命令行强制删除
os.system("del /f /q %s" % s_dir)
# 删除文件夹
try:
# 使用shutil模块
shutil.rmtree(s_dir)
except (PermissionError, OSError):
time.sleep(1)
shutil.rmtree(s_dir)
except Exception as error:
os.system('rd /s/q %s' % s_dir)