How to avoid “WindowsError: [Error 5] Access is denied”

后端 未结 7 1777
遥遥无期
遥遥无期 2020-12-06 05:12

There\'s the script to re-create folder:

# Remove folder (if exists) with all files
if os.path.isdir(str(os.path.realpath(\'..\') + \"\\\\my_folder\")):
             


        
7条回答
  •  一生所求
    2020-12-06 05:28

    Create your python script file. In this case you may copy it in C:\WINDOWS\system32. The script file is creating a folder named "Smaog"

    import os
    os.chdir('C:/Program Files')
    os.makedirs('Smaog')
    

    Create batch file, at any folder you like.

    echo off
    title Renaming Folder
    python sample.py
    pause
    

    Save the batch file. To run it, right click and choose Run as Administrator

    Though you may choose to do this instead if you don't want to put your python script in C:\WINDOWS\system32. In your batch file, indicate folder/directory where your python script file resides.

    echo off
    title Renaming Folder
    cd c:\Users\Smaog\Desktop
    python sample.py
    pause
    

    Then run it as Administrator as explained just above.

提交回复
热议问题