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
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to