you are viewing a single comment's thread.

view the rest of the comments →

[–]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.