[英]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
.我使用
python 3.9.1
中的os module
,我在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.我试图找出解决方案,建议在
Administrator mode
运行终端,但我使用的是 vs 代码。 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'
它给了我这个错误:
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
命令以管理员模式运行该文件。
runas /user:Administrator your_Command
If your command includes spaces, don't forget to add quotes.如果您的命令包含空格,请不要忘记添加引号。
runas /user:Administrator "your command"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.