Home >Backend Development >Python Tutorial >How to Move Files in Python: `os.rename()`, `os.replace()`, or `shutil.move()`?
Moving Files in Python: The Equivalent of mv
Python offers several functions to accomplish the task of moving a file, akin to the mv command in the terminal. These functions include os.rename(), os.replace(), and shutil.move().
Function Syntax
All three functions employ the same syntax:
os.rename("path/to/current/file.foo", "path/to/new/destination/for/file.foo") os.replace("path/to/current/file.foo", "path/to/new/destination/for/file.foo") shutil.move("path/to/current/file.foo", "path/to/new/destination/for/file.foo")
Key Considerations
The above is the detailed content of How to Move Files in Python: `os.rename()`, `os.replace()`, or `shutil.move()`?. For more information, please follow other related articles on the PHP Chinese website!