Python os.chdir() Method
Example
Change the current working directory:
#Import os module
import os
#Print current working directory
print("Current directory:" , os.getcwd())
#Create a new
directory
os.mkdir("mydir")
#Change current working directory
os.chdir("mydir")
#Print current working directory
print("Current directory now:" , os.getcwd())
Try it Yourself »
Definition and Usage
The os.chdir()
method changes the current working directory to a specific path.
Tip: The current working directory can be printed using the os.getcwd() method.
Syntax
os.chdir(path)
Parameter Values
Parameter | Description |
---|---|
path | Required. A relative or absolute file path of the new current directory |
Technical Details
Return Value: | None |
---|---|
Python Version: | 3.6 |