os.listdir() exceptions




Is os.listdir(path) the only method available for obtaining
directory/file list for the given path argument?

The reason I am asking is this: what if one wishes to obtain
a listing of, say the root directory (/), and in the case of using
the linux os, for example, one may encounter a directory
called: /.dbus, which is owned by root and not accessible
to a normal user, and may cause os.listdir() to throw an
OS.Error (permission denied) exception and to subsequently
terminate the os.listdir() method.

How does one get around this exception, to allow os.listdir()
to continue and to ignore these exceptions, whatever they
are, so that these exceptions can be handled with further
code as desired by the programmer?

I am tempted to use a pipe with /usr/bin/ls to get around
os.listdir(path), but this could break portability with other
os platforms?

Does anyone have an idea or a solution?

Thanks!
Dan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]