V
vsoler
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 ())
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:
c:\$recycle.bin\ => O:BADAI(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:SYDAI(D;;CC;;;WD)(A;;0x1200a9;;;WD)
(A;;FA;;;SY)(A;;FA;;;BA)
c:\documents and settings\ => O:SYDAI(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