如何删除/删除不为空的文件夹? [英] How do I remove/delete a folder that is not empty?
本文介绍了如何删除/删除不为空的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试删除不为空的文件夹时,出现访问被拒绝"错误.我尝试使用以下命令:os.remove("/folder_name")
.
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')
根据设计,rmtree
在包含只读文件的文件夹树上失败.如果要删除该文件夹而不管它是否包含只读文件,请使用
By design, rmtree
fails on folder trees containing read-only files. If you want the folder to be deleted regardless of whether it contains read-only files, then use
shutil.rmtree('/folder_name', ignore_errors=True)
这篇关于如何删除/删除不为空的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文