简体   繁体   中英

PermissionError: [WinError 5] Access is denied - Running the program in vs code

I am trying to write a program for deleting all the temp files on my system. I have using os module from python 3.9.1 and I am running it on VS Code . I tried to find out the solution, where it was suggested to run the terminal in Administrator mode , but I am using vs code. I found that there are no functions that can allow to change the mode of user. Below is the code,

import os
import shutil

os.chdir('c:\\Windows\\Temp')
for folderNames,subfolderNames,fileNames in os.walk('c:\\Windows\\Temp'):
    print('The folder is '+ folderNames)
    print('The subfolder in '+folderNames+' are: '+str(subfolderNames))
    print('The filenames in '+folderNames+' are:'+str(fileNames))
    print()

    for file in fileNames:
        os.unlink(file)
        #print(file)
    for folder in subfolderNames:
        shutil.rmtree(subfolderNames)
        #print(os.path.join('c:\\Windows\\Temp\\'),folder)



It gives me this error: PermissionError: [WinError 5] Access is denied: 'adobegc.log'

Could you please help...

Thank you swetha

You can try running the file in administrator mode using runas command.

runas /user:Administrator your_Command

If your command includes spaces, don't forget to add quotes.

runas /user:Administrator "your command"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM