On 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@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > Ah, ok.
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@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list