简体   繁体   English

PermissionError: [WinError 5] Access is denied while running in python 中遇到

[英]PermissionError: [WinError 5] Access is denied encountered while running in python

import glob
import os
import shutil




for name in os.listdir('C:/Users/Ajay/Downloads'):
    if name.endswith('.xlsx') or name.endswith('.csv'):
        os.rename('C:/Users/Ajay/Downloads', 'C:/Users/Ajay/Projects/GFD')
        print(name)





Traceback (most recent call last):
  File "C:\Users\Ajay\Projects\Desktop\automation.py", line 33, in <module>
    os.rename('C:/Users/Ajay/Downloads', 'C:/Users/Ajay/Projects/GFD')
PermissionError: [WinError 5] Access is denied: 'C:/Users/Ajay/Downloads' -> 'C:/Users/Ajay/Projects/GFD'

I have tried to use shutil.move but I get permission denied.我曾尝试使用 shutil.move,但权限被拒绝。 I have all the access to the directory as I am the admin, not sure why the issue still comes up.因为我是管理员,所以我拥有对目录的所有访问权限,但不确定为什么问题仍然出现。

That code would not move any files, but instead attempt to rename the directory every time.该代码不会移动任何文件,而是每次都尝试重命名目录。 As you indicated, you can use the shutil.move() method to do what you intend.正如您所指出的,您可以使用 shutil.move() 方法来执行您想要的操作。

The error is the same on both operations, therefore although you might have enough permission, you are probably executing the application from a non-privileged environment.这两个操作的错误是相同的,因此尽管您可能有足够的权限,但您可能正在从非特权环境中执行应用程序。 If you are the system administrator, this could usually be solved by running the program as an administrator:如果您是系统管理员,这通常可以通过以管理员身份运行程序来解决:

right click, run as administrator (directly on the python executable)右键单击,以管理员身份运行(直接在 python 可执行文件上运行)

or或者

Search for CMD, right click, run as administrator, execute python (application name)搜索CMD,右键,以管理员身份运行,执行python(应用名)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python-PermissionError:[WinError 5]访问被拒绝: - Python - PermissionError: [WinError 5] Access is denied: PermissionError: [WinError 5] 访问在 Python 中被拒绝 - PermissionError: [WinError 5] Access is denied in Python PermissionError: [WinError 5] 访问被拒绝 - PermissionError: [WinError 5] Access is denied PermissionError: [WinError 5] 访问被拒绝 - PermissionError: [WinError 5] Access denied python Selenium PermissionError:[WinError 5]访问被拒绝 - python Selenium PermissionError: [WinError 5] Access is denied Python - Mapreduce - PermissionError: [WinError 5] 访问被拒绝 - Python - Mapreduce - PermissionError: [WinError 5] Access is denied Python 错误:PermissionError:[WinError 5] 访问被拒绝 - Python Error: PermissionError: [WinError 5] Access is denied 使用 psutil 的 Python 程序在运行 8 小时后出现 PermissionError 失败:[WinError 5] 访问被拒绝 - 为什么? - Python program with psutil fails after 8 hours of running with PermissionError: [WinError 5] Access is denied - why? PermissionError: [WinError 5] Access is denied - 在 vs 代码中运行程序 - PermissionError: [WinError 5] Access is denied - Running the program in vs code PermissionError: [WinError 5] python 使用moviepy 写gif 被拒绝访问 - PermissionError: [WinError 5] Access is denied python using moviepy to write gif
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM