pathlibPathrename
PathlibPathrename refers to the rename operation provided by Python's pathlib module, typically used through Path.rename. It moves or renames a filesystem object to a new path and returns the destination path. This operation is designed for use within the same filesystem and is implemented as a method on Path instances.
Behavior and limitations: Path.rename will raise FileNotFoundError if the source does not exist and FileExistsError if
PathlibPathrename vs Path.replace: If you need to overwrite an existing destination, the Path.replace method provides semantics
Usage example: from pathlib import Path; p = Path('old_name.txt'); p.rename('new_name.txt'). This renames the file if the destination
Exceptions and safety: Common exceptions include FileNotFoundError, FileExistsError, PermissionError, and NotADirectoryError. It is advisable to check
See also: pathlib module, os.rename, os.replace, shutil.move.