简体   繁体   中英

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.

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. The OS of my computer where it works is 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.

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.

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.

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:

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM