概述
所以,我需要清理一个不是空的目录。
我创造了以下功能。用于测试我试图删除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上不为空的目录所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复