Os Chdir
# Python2.x Python os.chdir() Method
[ Python OS File/Directory Methods](#)
* * *
### Overview
The os.chdir() method is used to change the current working directory to the specified path.
### Syntax
The syntax for the **chdir()** method is as follows:
os.chdir(path)
### Parameters
* **path** -- The new path to switch to.
### Return Value
Returns True if access is allowed, otherwise returns False.
### Example
The following example demonstrates the use of the chdir() method:
#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys path = "/tmp"# Check current working directory retval = os.getcwd()print "Current working directory is %s" % retval # Change current working directory os.chdir( path )# Check modified working directory retval = os.getcwd()print "Directory changed successfully %s" % retval
The output of executing the above program is:
Current working directory is /www Directory changed successfully /tmp
[ Python OS File/Directory Methods](#)
YouTip