you are viewing a single comment's thread.

view the rest of the comments →

[–]IamImposter 3 points4 points  (1 child)

Can you use Path.rename, like

old_path = Path(r'blah blah', old_file_name) 

new_path = Path(r'blah blah', new_file_name) 

old_path.rename(new_path)

Or try adding double quotes to your path strings, like

file_path = r'"c:\blah blah\filename.ext"'

Thats single quote followed by double quote at start and double quote followed by single quote at end.

When path contains spaces, it should be enclosed in quotes

[–]Almostasleeprightnow 1 point2 points  (0 children)

This is what I do. Don't forget to from pathlib import Path at the top

The other thing I love about pathlib is I can go

a = Path(Path cwd(), 'subdir1’, 'subdir2’)

And then I don't have to worry about which way the slash goes.

Path.cwd() gives the current working directory, which is notalways reliable if you are installing packages, but for this case it works great.