简体   繁体   English

Python os.rename 问题: FileNotFoundError: [WinError 3] 系统找不到指定的路径

[英]Python os.rename issues: FileNotFoundError: [WinError 3] The system cannot find the path specified

I've browsed around for an answer to this before posting but couldn't find one that worked for me.在发布之前,我已经浏览过这个问题的答案,但找不到适合我的答案。

So essentially what I'm doing is taking a list of selenium elements, converting them to just text in a new array, and then trying to rename the file in my downloads directory.所以基本上我正在做的是获取 selenium 元素的列表,将它们转换为新数组中的文本,然后尝试在我的下载目录中重命名文件。
Upon reaching this loop I get the error.到达这个循环后,我得到了错误。
Does the new file have to exist in order to rename it?新文件是否必须存在才能重命名?

for count, filename in enumerate(os.listdir("C:/Users/user/Downloads")):
    dst1 = titlelist[count] + ".mp4"
    src = 'C:/Users/user/Downloads/'+ filename
    dst = 'C:/Users/user/Downloads/'+ dst1
    os.rename(src, dst)

Any help is appreciated.任何帮助表示赞赏。

To access Windows paths you need to use backslahes, and as the backslash is the escape character, you need to use two of them to include them in the string.要访问 Windows 路径,您需要使用反斜杠,并且由于反斜杠是转义字符,因此您需要使用其中两个来将它们包含在字符串中。

Instead of writing C:/Users/user you should write C:\\Users\\user而不是写C:/Users/user你应该写C:\\Users\\user

I know it sounds silly, but, you may wanna check the permissions on the folder and files我知道这听起来很傻,但是,您可能想检查文件夹和文件的权限

print("Source File Permission : %s" % os.access(src ,os.W_OK))
print("Destination File Permission : %s" % os.access(dst , os.W_OK))

in your case I would be tempted to try something like:在您的情况下,我很想尝试以下方法:

if os.access('C:/Users/user/Downloads/', os.W_OK):
    os.rename(src, dst)

暂无
暂无

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

相关问题 os.rename() 给出错误 FileNotFoundError: [WinError 2] The system cannot find the file specified: '0.jpg' -> '2.jpg' - os.rename( ) is giving the error FileNotFoundError: [WinError 2] The system cannot find the file specified: '0.jpg' -> '2.jpg' os.rename错误:系统找不到指定的路径 - os.rename error: The System Cannot Find The Path Specified os.rename 错误“系统找不到指定的路径” - os.rename Error “The system cannot find the path specified” FileNotFoundError: [WinError 3] 系统找不到指定的路径。 视窗操作系统 - FileNotFoundError: [WinError 3] The system cannot find the path specified. Windows OS Python:FileNotFoundError:[WinError 3]系统找不到指定的路径:” - Python: FileNotFoundError: [WinError 3] The system cannot find the path specified: '' FileNotFoundError:[WinError 3]系统找不到指定的路径:” - FileNotFoundError: [WinError 3] The system cannot find the path specified: '' Python:FileNotFoundError:[WinError 3]系统找不到指定的路径: - Python: FileNotFoundError: [WinError 3] The system cannot find the path specified: FileNotFoundError: [WinError 3] 系统找不到指定的路径 '\\\\xml\\\\' - FileNotFoundError: [WinError 3] The system cannot find the path specified '\\xml\\' FileNotFoundError: [WinError 3] 系统找不到指定的路径:...chromedriver.exe - FileNotFoundError: [WinError 3] The system cannot find the path specified:...chromedriver.exe JupyterNotebook: FileNotFoundError: [WinError 3] 系统找不到指定的路径 - JupyterNotebook: FileNotFoundError: [WinError 3] The system cannot find the path specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM