How to get a directory file descriptor?

Cong Ma cma at mail.bnu.edu.cn
Tue Nov 25 03:02:56 EST 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
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 os.open() for files, or the Linux dirfd()
call, which returns an integer for a pointer to a DIR stream.

Regards,
Cong.




More information about the Python-list mailing list