Re: How to get a directory file descriptor?

2008-11-26 Thread Cong Ma
alex23 wrote: On Nov 26, 3:26 pm, greg [EMAIL PROTECTED] wrote: os.O_DIRECTORY must be fairly new -- it doesn't exist in my 2.5 installation. But os.O_RDONLY seems to work just as well for this purpose. Which OS are you using? Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3

Re: How to get a directory file descriptor?

2008-11-26 Thread Nick Craig-Wood
Cong Ma [EMAIL PROTECTED] wrote: Thanks for your reply. I checked my Python 2.5 install on Linux and there's the O_DIRECTORY flag. However this is not mentioned anywhere in the Library Reference. There's another question regarding to this flag though: I checked the manual of the

Re: How to get a directory file descriptor?

2008-11-26 Thread Cong Ma
Nick Craig-Wood wrote: Here is how you do exactly that in python using ctypes from ctypes import CDLL, c_char_p, c_int, Structure, POINTER from ctypes.util import find_library class c_dir(Structure): Opaque type for directory entries, corresponds to struct DIR c_dir_p =

Re: How to get a directory file descriptor?

2008-11-26 Thread alex23
On Nov 26, 11:07 pm, Steve Holden [EMAIL PROTECTED] wrote: alex23 wrote: I'm pretty certain it was present under Windows XP as well. Since these two are the exact same version I presume O_DIRECTORY is not meaningful on Windows. Anyway, when I try to use O_RDONLY on Vista I get Permission

Re: How to get a directory file descriptor?

2008-11-26 Thread Steve Holden
alex23 wrote: On Nov 26, 3:26 pm, greg [EMAIL PROTECTED] wrote: os.O_DIRECTORY must be fairly new -- it doesn't exist in my 2.5 installation. But os.O_RDONLY seems to work just as well for this purpose. Which OS are you using? Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3

Re: How to get a directory file descriptor?

2008-11-26 Thread alex23
On Nov 26, 8:56 pm, Cong Ma [EMAIL PROTECTED] wrote: Thanks for your reply. I checked my Python 2.5 install on Linux and there's the O_DIRECTORY flag. However this is not mentioned anywhere in the Library Reference. Yes, I just noticed that myself.        O_DIRECTORY               If

Re: How to get a directory file descriptor?

2008-11-26 Thread Terry Reedy
Steve Holden wrote: import os hasattr(os, 'O_DIRECTORY') True I'm pretty certain it was present under Windows XP as well. f = os.open(., os.O_DIRECTORY) Traceback (most recent call last): File stdin, line 1, in module AttributeError: 'module' object has no attribute 'O_DIRECTORY' The

Re: How to get a directory file descriptor?

2008-11-26 Thread greg
Steve Holden wrote: Anyway, when I try to use O_RDONLY on Vista I get Permission denied: According to the library ref, fchdir() is Unix-only, so there probably isn't a use case for getting a file descriptor for a directory on Windows in the first place. -- Greg --

Re: How to get a directory file descriptor?

2008-11-25 Thread Cong Ma
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()):

Re: How to get a directory file descriptor?

2008-11-25 Thread r0g
Cong Ma wrote: 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

Re: How to get a directory file descriptor?

2008-11-25 Thread r0g
r0g wrote: Cong Ma wrote: 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

Re: How to get a directory file descriptor?

2008-11-25 Thread alex23
On Nov 25, 5:05 pm, Cong Ma [EMAIL PROTECTED] wrote: 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? Try: os.open('dirname', os.O_RDONLY) Check os for a list of the valid flag

Re: How to get a directory file descriptor?

2008-11-25 Thread alex23
On Nov 25, 9:53 pm, alex23 [EMAIL PROTECTED] wrote: On Nov 25, 5:05 pm, Cong Ma [EMAIL PROTECTED] wrote: 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? Try:

Re: How to get a directory file descriptor?

2008-11-25 Thread D'Arcy J.M. Cain
On Tue, 25 Nov 2008 16:02:56 +0800 Cong Ma [EMAIL PROTECTED] wrote: Can you give me some hint on getting a directory file descriptor in Python? for each in os.listdir(os.getcwd()): print each Your code fetches a bunch of strings representing file names in the working directory, which is

Re: How to get a directory file descriptor?

2008-11-25 Thread Baptiste Carvello
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

Re: How to get a directory file descriptor?

2008-11-25 Thread alex23
On Nov 26, 12:31 am, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote: Is this what you want? ofiles = [open(x) for x in os.listdir(os.getcwd())] 'open' returns a file object, whereas the OP is after file descriptors, which are returned by 'os.open'. --

Re: How to get a directory file descriptor?

2008-11-25 Thread Cong Ma
alex23 wrote: On Nov 26, 12:31 am, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote: Is this what you want? ofiles = [open(x) for x in os.listdir(os.getcwd())] 'open' returns a file object, whereas the OP is after file descriptors, which are returned by 'os.open'. --

Re: How to get a directory file descriptor?

2008-11-25 Thread alex23
On Nov 26, 1:34 pm, Cong Ma [EMAIL PROTECTED] wrote: So if I can't seem to get directory file descriptors, the only way to use os.fchdir() in Python is to embed Python in C code? This doesn't work for you? import os dirfd = os.open(directory-name, os.O_DIRECTORY) os.fchdir(dirfd) Are you

Re: How to get a directory file descriptor?

2008-11-25 Thread greg
alex23 wrote: import os dirfd = os.open(directory-name, os.O_DIRECTORY) os.fchdir(dirfd) os.O_DIRECTORY must be fairly new -- it doesn't exist in my 2.5 installation. But os.O_RDONLY seems to work just as well for this purpose. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get a directory file descriptor?

2008-11-25 Thread alex23
On Nov 26, 3:26 pm, greg [EMAIL PROTECTED] wrote: os.O_DIRECTORY must be fairly new -- it doesn't exist in my 2.5 installation. But os.O_RDONLY seems to work just as well for this purpose. Which OS are you using? Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu

How to get a directory file descriptor?

2008-11-24 Thread Cong Ma
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

Re: How to get a directory file descriptor?

2008-11-24 Thread r0g
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