You can use os.rename(), os.replace(), or shutil.move() methods in Python to rename, replace or move a file in Python as shown in below examples –
1 2 3 4 5 6 |
import os import shutil 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") |