如何使用Python删除/删除不为空的文件夹? [英] How do I remove/delete a folder that is not empty with Python?

查看:525
本文介绍了如何使用Python删除/删除不为空的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试删除不为空的文件夹时,我收到访问被拒绝错误。我尝试使用以下命令: os.remove(/ folder_name)



删除/删除不为空的文件夹/目录最有效的方法是什么?

解决方案

  import shutil 

shutil.rmtree('/ folder_name')
pre>

标准库参考:shutil.rmtree


I am getting an 'access is denied' error when I attempt to delete a folder that is not empty. I used the following command in my attempt: os.remove("/folder_name").

What is the most effective way of removing/deleting a folder/directory that is not empty?

解决方案

import shutil

shutil.rmtree('/folder_name')

Standard Library Reference: shutil.rmtree.

这篇关于如何使用Python删除/删除不为空的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆