Moving Files in Python
In Python, you can move a file using various methods, including:
os.rename()
import os os.rename("path/to/current/file.foo", "path/to/new/destination/for/file.foo")
os.replace()
import os os.replace("path/to/current/file.foo", "path/to/new/destination/for/file.foo")
shutil.move()
import shutil shutil.move("path/to/current/file.foo", "path/to/new/destination/for/file.foo")
These methods all have the same syntax. The first argument is the path to the current file, and the second argument is the path to the new destination.
Considerations
The above is the detailed content of How Can I Move Files in Python?. For more information, please follow other related articles on the PHP Chinese website!