Reading the access attributes of directories in Windows

vsoler vicente.soler at gmail.com
Sat Aug 21 13:51:57 CEST 2010


On Aug 21, 8:10 am, Tim Golden <m... at timgolden.me.uk> wrote:
> On 20/08/2010 11:54 PM, vsoler wrote:
>
> > I'am testing your library. I am mainly interested in knowing the
> > access attributes of directories in the local(C:\) or shared unit(W:\)
> > of my system.
>
> > Using your script with 'c:\\' I get an error message saying... 'file
> > exists but it is a directory' and I cannot go any further.
>
> > Of course, the problem is that I am using "fs.file" when I should be
> > using something different.
>
> Either use fs.dir (if you know it's a directory) or fs.entry (if it
> could be a file or a directory; the code will dispatch to the right one).
>
> If you only want the directories immediately some directory,
> you could do this:
>
> <code>
> from winsys import fs, security
>
> root = fs.file (sys.executable).path  # or fs.dir ("w:/") etc.
> for d in root.dirs (ignore_access_errors=True):
>    print (d, "=>", d.security ()) # or whatever
>
> </code>
>
> If you want to walk the tree of directories looking at permissions, then:
>
> <code>
> import os, sys
> from winsys import fs
>
> root = fs.file (sys.executable).path
> for dirpath, _, _ in root.walk ():
>    print (dirpath, "=>", dirpath.security ())
>
> </code>
>
> > Reading the doc I have found that I should be using os.walk(...),
> > which works, but then I cannot use fs.file
>
> In fact, even if you did for some reason use os.walk, you can
> easily wrap the returned filenames using fs.entry:
>
> <code>
> import os, sys
> from winsys import fs
>
> root = os.path.dirname (sys.executable)
> for dirpath, filenames, dirnames in os.walk (root):
>    print (dirpath, "=>", fs.entry (dirpath).security ())
>
> </code>
>
> TKG

Tim,

I appreciate the time and effort that you are putting in this post.

Personally, I am impressed of the power of python, your winsys
library, and overall, how easy it is to customize the scripting of
one's day to day needs.

I have started testing your first script

from winsys import fs, security
root = fs.dir ("c:/")
for d in root.dirs (ignore_access_errors=True):
   print (d, "=>", d.security ())

Howwvwer, I am getting an error:

>>> ================================ RESTART ================================
>>>
c:\$recycle.bin\ => O:BAD:PAI(A;;FA;;;BA)(A;OICIIO;GA;;;BA)(A;;FA;;;SY)
(A;OICIIO;GA;;;SY)(A;;0x1201ad;;;BU)
c:\aeat\ => O:BAD:AI(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;FA;;;SY)
(A;OICIIOID;GA;;;SY)(A;OICIID;0x1200a9;;;BU)(A;ID;0x1301bf;;;AU)
(A;OICIIOID;SDGXGWGR;;;AU)
c:\archivos de programa\ => O:SYD:PAI(D;;CC;;;WD)(A;;0x1200a9;;;WD)
(A;;FA;;;SY)(A;;FA;;;BA)
c:\documents and settings\ => O:SYD:PAI(D;;CC;;;WD)(A;;0x1200a9;;;WD)
(A;;FA;;;SY)(A;;FA;;;BA)
c:\hp\ => O:SYD:AI(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;FA;;;SY)
(A;OICIIOID;GA;;;SY)(A;OICIID;0x1200a9;;;BU)(A;ID;0x1301bf;;;AU)
(A;OICIIOID;SDGXGWGR;;;AU)
Traceback (most recent call last):
  File "C:/Users/Vicente/Documents/VS/Python/test6.py", line 5, in
<module>
    print(d, "=>",d.security())
  File "C:\Python31\lib\site-packages\winsys\fs.py", line 1044, in
security
    return security.security (self, options=options)
  File "C:\Python31\lib\site-packages\winsys\security.py", line 585,
in security
    return Security.from_object (str (obj), obj_type, options=options)
  File "C:\Python31\lib\site-packages\winsys\security.py", line 475,
in from_object
    sd = wrapped (win32security.GetNamedSecurityInfo, obj,
object_type, options)
  File "C:\Python31\lib\site-packages\winsys\exc.py", line 55, in
_wrapped
    raise exception (errno, errctx, errmsg)
winsys.security.x_security: (5, 'GetNamedSecurityInfo', 'Acceso
denegado.')
>>>

I am using a system in the Spanish language. As you can see in the
last line, 'Acceso denegado' or 'Access denied' even though the flag
"ignore_access_errors" is set to True.

I am using python 3.1 on Windows 7. What do you think is the origin of
this problem?

Vicente Soler



More information about the Python-list mailing list