How to get a directory file descriptor?

Cong Ma cma at
Tue Nov 25 09:02:56 CET 2008

r0g wrote:
> Cong Ma wrote:
>> 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.
> for each in os.listdir(os.getcwd()):
>   print each
> Roger.
> --

It seemed I didn't make it clearly enough...

Your code fetches a bunch of strings representing file names in the working
directory, which is fine. But what I want is something like an integer file
descriptor, like the one returned by for files, or the Linux dirfd()
call, which returns an integer for a pointer to a DIR stream.


More information about the Python-list mailing list