Windows错误5:尝试删除Windows中的目录时,访问被拒绝 [英] Windows error 5: Access is denied when trying delete a directory in windows

查看:233
本文介绍了Windows错误5:尝试删除Windows中的目录时,访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除目录,但是当我运行代码时,它给出了Windows错误5:访问被拒绝.这是我的代码:在Release文件夹中,有一个名为OD的文件夹.

i am trying to delete a directory but when i run the code it gives windows error 5: access is denied. here is my code: in the Release folder, there is a folder called OD.

if os.path.exists(os.path.join(get_path_for_output,'Release')):
        shutil.rmtree(os.path.join(get_path_for_output,'Release')) 

错误类似:

WindowsError: [Error 5] Access is denied: 'C:\\Users\\marahama\\Desktop\\Abdur_Release\\Release\\OD\\automations\\GEM\\FMS_adapter.py'

推荐答案

这是由于文件权限问题引起的.

This was due to the file permissions issue.

您需要具有在该文件上执行该任务的权限.

You need to have the permissions to perform that task on that file.

要获取与文件关联的权限,请使用os.stat(fileName)

To get the permissions associated with a file, useos.stat(fileName)

您可以使用os.access(fileName, os.W_OK)

然后,更改权限,os.chmod(fileName,permissionNumeric).

例如:os.chmod(fileName, '0777')

要更改正在执行的当前文件的权限, 使用os.chmod(__file__, '0777')

To change the permission for the current file that is being executed, use os.chmod(__file__, '0777')

这篇关于Windows错误5:尝试删除Windows中的目录时,访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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