所以,我需要清理一个不是空的目录。
我创造了以下功能。用于测试我试图删除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上不为空内容请搜索靠谱客的其他文章。
发表评论 取消回复