How to get a directory file descriptor?

Baptiste Carvello baptiste13z at free.fr
Tue Nov 25 10:59:40 CET 2008


Cong Ma a écrit :
> Dear all,
> 
> Can you give me some hint on getting a directory file descriptor in Python?
> Besides, what's good about os.fchdir() if I can't get a directory fd in the
> first place?
> 
> Thanks for your reply.
> 
> Regards,
> Cong.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Hello,

I believe you want os.open :

Python 2.5.2 (r252:60911, Sep 29 2008, 21:10:35)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> d=os.open('mydir',os.O_RDONLY)
 >>> d
3
 >>> os.fchdir(d)
 >>> os.getcwd()
'/home/baptiste/mydir'
 >>>

Cheers,
Baptiste




More information about the Python-list mailing list