Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 905
ThePrinceofPython Avatar asked Feb 15 '15 16:02

ThePrinceofPython


1 Answers

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.
like image 71
Aaron Avatar answered Oct 25 '22 02:10

Aaron