为什么会出现WindowsError:[错误5]访问被拒绝? [英] Why am i getting WindowsError: [Error 5] Access is denied?
本文介绍了为什么会出现WindowsError:[错误5]访问被拒绝?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试创建将文件夹添加到程序文件中的程序-收到此错误:
Trying to create program that adds folders into program files-recieving this error:
WindowsError: [Error 5] Access is denied 'C:\\Program Files\\IMP'
这是我的代码
import os, sys, random
numb= 1
x=True
while x==True:
newpath = ((r'C:\Program Files\IMP\folder_%s') % (numb))
if not os.path.exists(newpath):
os.makedirs(newpath)
numb=numb+1
if numb==11:
x=False
推荐答案
因为您必须具有系统管理员权限"才能在C:\Program Files
下创建目录.
Because you have to have the "system administrator privileges" to create dirs under C:\Program Files
.
因此,请尝试以系统管理员权限运行脚本.
So try run the script with system administrators privilege.
以管理员身份启动命令提示符
To start a command prompt as an administrator
- 单击开始.
- 在开始搜索"框中,键入
cmd
,然后按 CTRL + SHIFT + ENTER . - 运行python脚本.
- Click Start.
- In the Start Search box, type
cmd
, and then press CTRL+SHIFT+ENTER. - Run the python script.
这篇关于为什么会出现WindowsError:[错误5]访问被拒绝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文