Python os.fchdir() Method
Example
Change the current directory to the path already opened by os.open():
#import os module
import os
# open a directory with os.open
method
fd = os.open("mydir", os.O_RDONLY)
#change
the currently running directory
os.fchdir(fd)
#Print the updated
directory path
print ("Updated directory:" , os.getcwd())
Try it Yourself »
Definition and Usage
The os.fchdir()
method changes the current
working directory to the path which is already opened by os.open().
The os.open()
method returns the file descriptor which is further used by
os.fchdir() to change the working directory. A file descriptor is an
indicator that indicates an open file or folder in a system's operating system.
Note: os.fchdir()
works only on UNIX system.
Syntax
os.fchdir(fd)
Parameter Values
Parameter | Description |
---|---|
fd | Required. A file descriptor from os.open() . This descriptor must refer
to an open directory, not an open file. |
Technical Details
Return Value: | None |
---|---|
Python Version: | 2.3 |