简体   繁体   English

os.rename无法在AWS Workspace上工作,FileNotFoundError

[英]os.rename Not Working On AWS Workspace, FileNotFoundError

This is strange and I'm not sure if it's due to me environment or not (appears so). 这很奇怪,我不确定是否是我的环境造成的(如此看来)。

On may computer I try to run the following and it works fine 在可能的计算机上,我尝试运行以下命令,它运行正常

import os
os.rename('C:\\Users\\travissimpson\\Downloads\\filename-test.zip','C:\\Users\\travissimpson\\Downloads\\filename-test2.zip')

On my AWS Workspace (AWS VM) I run the following and I get a file not found error. 在我的AWS Workspace(AWS VM)上,运行以下命令,但出现文件未找到错误。

import os
os.rename('D:\\Users\\travissimpson\\Downloads\\filename-test.zip','D:\\Users\\travissimpson\\Downloads\\filename-test2.zip')

Result: 结果:

FileNotFoundError: [WinError 2] The system cannot find the file specified: 
'D:\\Users\\travissimpson\\Downloads\\filename-test.zip' -> 
'D:\\Users\\travissimpson\\Downloads\\filename-test2.zip'

The OS of the AWS Workspace is Windows Server 2016 Datacenter. AWS Workspace的操作系统是Windows Server 2016数据中心。 The OS of my computer where it works is Windows Server 2012 R2 我可以使用的计算机的操作系统是Windows Server 2012 R2

You can use Python script with os.listdir() to list files in D:\\\\ , later in D:\\\\Users , etc. to check what you have in folders. 您可以将Python脚本与os.listdir()一起使用,以列出D:\\\\中的文件,然后再列出D:\\\\Users等中的文件,以检查文件夹中的内容。

You can also display names with some char before and after - ie. 您还可以在名称前后显示一些字符-即。 "|" in print(f"|{name}|") - to see if there is no spaces in name (at the beginning and at the end) which you may not see normally. print(f"|{name}|") -查看名称中是否没有空格(在开头和结尾),而这些空格通常不会出现。

import os

for item in os.listdir('D:\\'):
    print(f"|{item}|")
    #print("|{}|".format(item))  # older pythons

for item in os.listdir('D:\\Users'):
    print(f"|{item}|")
    #print("|{}|".format(item))  # older pythons

# etc.

This way you can see what names see Python. 这样,您可以看到Python看到的名称。

There is no magic. 没有魔术。 If you get "File not found" then the file is not there, point. 如果出现“找不到文件”,则文件不存在,指向。

To confirm, on your remote Windows box try: 要确认,请在您的远程Windows框中尝试:

dir D:\Users\travissimpson\Downloads\filename-test.zip

–– I am sure this will tell you something like "File not found". -我确信这会告诉您“找不到文件”之类的信息。

Disclaimer: I didn't use Windows since the XXth century :) 免责声明:自二十世纪以来我一直没有使用Windows :)

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

相关问题 os.rename 返回 FilenotfoundError - os.rename returns FilenotfoundError 尝试使用os.rename时出现FileNotFoundError - FileNotFoundError when trying to use os.rename 在 Python 中使用 os.rename() 时出现 FileNotFoundError - FileNotFoundError when using os.rename() in Python OS.rename()无法与tkinter一起使用 - OS.rename() not working with tkinter os.rename()在我的python脚本中不起作用 - os.rename() not working in my python script 被困在os.rename() - Stuck at os.rename() Python os.rename 问题: FileNotFoundError: [WinError 3] 系统找不到指定的路径 - Python os.rename issues: FileNotFoundError: [WinError 3] The system cannot find the path specified 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 没有成功重命名子目录,抛出 FileNotFoundError 尽管使用 glob.glob 和 recursive=True - os.rename does not succeed in renaming in subdirectories, throws FileNotFoundError despite using glob.glob with recursive=True FileNotFoundError 使用 os.rename 时,但在调用 print function 时没有 - FileNotFoundError when using os.rename, but not when calling up print function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM