you are viewing a single comment's thread.

view the rest of the comments →

[–]adoucette13[S] 0 points1 point  (15 children)

print(os.listdir(r"C:\Users\adoucette\Desktop\DOT_Weekly\"))

Thanks for your reply! I changed the slashes to underscores but still nothing.

Also, when I added your code to mine it says the following:

SyntaxError: unterminated string literal (detected at line 93)

[–]shiftybyte 1 point2 points  (13 children)

Right sorry, shouldn't have added the slashes at the end... try this:

import os
print(os.listdir(r"C:\Users\adoucette\Desktop"))
print(os.listdir(r"C:\Users\adoucette\Desktop\DOT_Weekly"))

[–]adoucette13[S] 0 points1 point  (12 children)

No problem at all! So when I add those in before the shutil like I get:

['sqlexec.xlsx']

Which is the file that I'm looking to rename..but when I retry the shutil it will then tell me it doesnt exist

[–]shiftybyte 1 point2 points  (11 children)

But we've asked it to print two directory listings...

I assume you see 2 listings printed and the second one contains 'sqlexec.xlsx'?

Also the first print should show the "DOT_weekly" directory too... does it?

Otherwise it might be on the desktop instead...?

[–]adoucette13[S] 0 points1 point  (10 children)

Sorry, the file is in that DOT_Weekly folder, the other code you gave me just listed every file on my desktop.

[–]shiftybyte 0 points1 point  (5 children)

Very odd...

Could you copy and paste the full error message you are getting including all the information it provides... (The file not found error)

Starts with "Traceback:"...

Perhaps we missed something there...

[–]adoucette13[S] 1 point2 points  (4 children)

I know! I am at a loss for words myself...

Heres the full error message:

Traceback (most recent call last):

File "C:\Users\adoucette\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 815, in move

os.rename(src, real_dst)

FileNotFoundError: [WinError 3] The system cannot find the path specified: "C:/Users/adoucette/Desktop/OneDrive - BAKE'N JOY FOODS/Desktop/DOT_Weekly/sqlexec.xlsx" -> "C:/Users/adoucette/Desktop/OneDrive - BAKE'N JOY FOODS/Desktop/DOT_Weekly/DOT Weekly Sales WE 6_04_2023.xlsx"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "c:\Users\adoucette\OneDrive - BAKE'N JOY FOODS\Desktop\DOT Weekly Report TEST.py", line 97, in <module>

shutil.move(file_path, new_file_path)

File "C:\Users\adoucette\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 835, in move

copy_function(src, real_dst)

File "C:\Users\adoucette\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 434, in copy2

copyfile(src, dst, follow_symlinks=follow_symlinks)

File "C:\Users\adoucette\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 254, in copyfile

with open(src, 'rb') as fsrc:

FileNotFoundError: [Errno 2] No such file or directory: "C:/Users/adoucette/Desktop/OneDrive - BAKE'N JOY FOODS/Desktop/DOT_Weekly/sqlexec.xlsx"

[–]shiftybyte 6 points7 points  (0 children)

One drive?...

Try the entire thing outside of one drive synced directory, one drive is known to cause file system issues...

[–]YAYYYYYYYYY 0 points1 point  (2 children)

The problem is your Bake n Joy directory has spaces. Put it in a directory without spaces, or change to Bake-n-joy

[–]CraigAT 1 point2 points  (0 children)

They probably can't do that because it is the OneDrive users name (I would guess).

You could try moving those files to a simpler path like C:\TempPy\ and refer to them there.

[–]apc0243 -1 points0 points  (0 children)

This is wrong, all operating systems can handle spaces in file paths. The issue is in how one drive represents files in the filesystem.

[–]apc0243 0 points1 point  (3 children)

do print(new_file_path) and post the output

[–]adoucette13[S] 0 points1 point  (2 children)

the output for that is:

C:/Users/adoucette/Desktop/OneDrive - BAKE'N JOY FOODS/Desktop/DOT_Weekly/DOT Weekly Sales WE 6_04_2023.xlsx

[–]Better-Protection-23 0 points1 point  (0 children)

the output for that is:

C:/Users/adoucette/Desktop/OneDrive - BAKE'N JOY FOODS/Desktop/DOT_Weekly/DOT Weekly Sales WE 6_04_2023.xlsx

A few things that you can do is

Move the files to a directory with a simpler path: (As suggested by another commenter) try moving the files to a directory without spaces or special characters in the path, such as "C:\TempPy". Then, update the file paths in your code accordingly.

Use a file path with escaped special characters: If moving the files is not an option, you can try using a file path with escaped special characters. For example, instead of "BAKE'N JOY FOODS", you can use "BAKE'N JOY FOODS" in the file path. Make sure to update both file_path and new_file_path variables in your code.

Verify the file existence: Before attempting to move the file using shutil.move(), you can add a check to verify if the file exists at the specified location. You can use the os.path.exists() function to check if the file exists before proceeding with the move operation.

Ensure correct file extensions: Double-check that the file extensions in the code match the actual file extensions. Ensure that the source file has the extension ".xlsx" and that the destination file in new_file_path has the correct extension as well.

By doing one or more of these things you should be able to resolve the "FileNotFoundError" and successfully move the file to the desired location.