python move directory code example

Example 1: python move file

# To move a file in Python, use one of the following:
import os
import shutil

os.rename("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")
os.replace("path/to/current/file.foo", "path/to/new/destination/for/file.foo")

# In the first two cases the directory in which the new file
# is being created must already exist.

Example 2: change directory in python os

import os

path = "C:\Users\Your\Directory"

os.chdir(path)

Example 3: change directory in python script

os.chdir(os.path.dirname(__file__))