我是靠谱客的博主 和谐大碗,这篇文章主要介绍python删除空目录_删除python上不为空的目录,现在分享给大家,希望可以做个参考。

所以,我需要清理一个不是空的目录。

我创造了以下功能。用于测试我试图删除JDK安装的原因def clean_dir(location):

fileList = os.listdir(location)

for fileName in fileList:

fullpath=os.path.join(location, fileName)

if os.path.isfile(fullpath):

os.chmod(fullpath, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

os.remove(location + "/" + fileName)

elif os.path.isdir(fullpath):

if len(os.listdir(fullpath)) > 0:

clean_dir(fullpath)

#os.rmdir(location + "/" + fileName)

shutil.rmtree(location + "/" + fileName)

return

我试图使用rmtree和rmdir,但是失败了。在

我使用rmtree得到的错误是:OSError: Cannot call rmtree on a symbolic link

这是我在使用rmdir时得到的错误:OSError: [Errno 66] Directory not empty:

'/tmp/jdk1.8.0_25/jre/lib/amd64/server'

代码在windows上可以正常工作。但由于某些原因,它在linux上失败了。在

最后

以上就是和谐大碗最近收集整理的关于python删除空目录_删除python上不为空的目录的全部内容,更多相关python删除空目录_删除python上不为空内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部