0

Hello i am trying to delete a directory which is like a temporary file storage. however it does not work and keeps throwing the same erros

     directory = ("C:\\Users\\Bradley\\Desktop\\Log in system\\TempFiles")
     os.remove(directory)

here is the error:

     PermissionError: [WinError 5] Access is denied: 
     'C:\\Users\\Bradley\\Desktop\\Log in system\\TempFiles'
bradley plater
  • 1,272
  • 2
  • 9
  • 16

1 Answers1

0
  1. Check your permissions

  2. os.remove requires a file path, and raises OSError if path is a directory. If path is a directory, OSError is raised; see rmdir() below to remove a directory.

    Try this:

    os.rmdir("C:\\Users\\Bradley\\Desktop\\Log in system\\TempFiles")
    
  3. In other way you can use this trick ;) :

    import subprocess
    subprocess.call(['runas', '/user:Administrator', 'Your command'])
    

And, according to this post, you can run your program as an administrator by right click and run as administrator.

Community
  • 1
  • 1
RaminNietzsche
  • 2,683
  • 1
  • 20
  • 34
  • I just tried implementing it into my code and it has come back saying that the directory does not exist when it actually does? – bradley plater Apr 03 '17 at 19:56