Why am i getting WindowsError: [Error 5] Access is denied?

最后都变了- 提交于 2019-11-26 22:00:48

问题


Trying to create program that adds folders into program files-recieving this error:

WindowsError: [Error 5] Access is denied 'C:\\Program Files\\IMP'

Here is my code

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

回答1:


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

  1. Click Start.
  2. In the Start Search box, type cmd, and then press CTRL+SHIFT+ENTER.
  3. Run the python script.



回答2:


Right click on file (which file/folder's permissions needed to execute the script) go properties, security and enable all permissions, little checkboxes -> ALLOW: "every application package & limited application package & trusted installer"

this is it :)



来源:https://stackoverflow.com/questions/28528020/why-am-i-getting-windowserror-error-5-access-is-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!