简体   繁体   English

PermissionError: [WinError 5] Access is denied - 在 vs 代码中运行程序

[英]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.

相关问题 PermissionError: [WinError 5] 访问被拒绝 - PermissionError: [WinError 5] Access is denied PermissionError: [WinError 5] 访问被拒绝 - PermissionError: [WinError 5] Access denied PermissionError:[WinError 5]访问被拒绝:'C:\\ Program Files \\ Anaconda3 \\ pkgs \\ vs2015_runtime-14.0.25123-0.tmp - PermissionError: [WinError 5] Access is denied: 'C:\\Program Files\\Anaconda3\\pkgs\\vs2015_runtime-14.0.25123-0.tmp 使用 psutil 的 Python 程序在运行 8 小时后出现 PermissionError 失败:[WinError 5] 访问被拒绝 - 为什么? - Python program with psutil fails after 8 hours of running with PermissionError: [WinError 5] Access is denied - why? Python-PermissionError:[WinError 5]访问被拒绝: - Python - PermissionError: [WinError 5] Access is denied: 执行以下代码时出错(PermissionError: [WinError 5] Access is denied) - Getting Error (PermissionError: [WinError 5] Access is denied) when Execute below code pytesseract 给出错误 PermissionError: [WinError 5] Access is denied - pytesseract gives an error PermissionError: [WinError 5] Access is denied PermissionError: [WinError 5] 访问被拒绝 OS.remove - PermissionError: [WinError 5] Access is denied OS.remove PermissionError: [WinError 5] 访问被拒绝 jupyter 内核 - PermissionError: [WinError 5] Access is denied jupyter kernel PermissionError: [WinError 5] 使用 distutils 后访问被拒绝 - PermissionError: [WinError 5] Access is denied after using distutils
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM