PyDocs

Nav

File and Directory Access

Path.rename

pathlib

method of Path (source)
  • Path.rename(target)
Rename this path to the target path.

The target path may be absolute or relative. Relative paths are
interpreted relative to the current working directory, *not* the
directory of the Path object.

Returns the new Path instance pointing to the target path.
Changed in 3.8
  • 3.8: Added return value, return the new Path instance.
1 Example
>>> p = Path('foo')
>>> p.open('w').write('some text')
9
>>> target = Path('bar')
>>> p.rename(target)
PosixPath('bar')
>>> target.open().read()
'some text'
from the Python docs
See Also
No see-alsos for pathlib/Path.rename
0 Notes
No notes for Path.rename