How to get a directory file descriptor?

Steve Holden steve at holdenweb.com
Wed Nov 26 14:07:20 CET 2008


alex23 wrote:
> On Nov 26, 3:26 pm, greg <g... at cosc.canterbury.ac.nz> 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 4.2.3-2ubuntu7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import os
>>>> hasattr(os, 'O_DIRECTORY')
> True
> 
> I'm pretty certain it was present under Windows XP as well.
> 

OK, here's a little mystery. This is Vista (spit):

Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Users\sholden>python
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> 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'
>>> hasattr(os, 'O_DIRECTORY')
False
>>>

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 denied":

>>> f = os.open(os.path.abspath("Documents"), os.O_RDONLY)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 13] Permission denied: 'C:\\Users\\sholden\\Documents'

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list