|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
os.listdir() exceptionsIs 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 _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
|
|
Re: os.listdir() exceptionsOn 10/24/2009 08:30 AM, Daniel B. Thurman wrote:
> 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 > > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@... > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > I think I figured it out and it was a no-brainer! try: # Even if an exception is thrown, # it obtains all the file lists anyway files = os.listdir(path) except: # Handle specifics here or pass _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
|
|
Re: os.listdir() exceptionsOn Sat, 2009-10-24 at 08:30 -0700, Daniel B. Thurman wrote:
> Is os.listdir(path) the only method available for obtaining > directory/file list for the given path argument? how is this relevant to gtk+ application development? ciao, Emmanuele. _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
|
|
Re: os.listdir() exceptionsOn 10/25/2009 04:46 AM, Emmanuele Bassi wrote:
> On Sat, 2009-10-24 at 08:30 -0700, Daniel B. Thurman wrote: > >> Is os.listdir(path) the only method available for obtaining >> directory/file list for the given path argument? >> > how is this relevant to gtk+ application development? > > ciao, > Emmanuele. > > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@... > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > just threw it out there so... sorry to bust your bubble. ;) _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
| Free embeddable forum powered by Nabble | Forum Help |