check whether directory is readable

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Aug 23 07:38:35 EDT 2005


eels <eels at nikocity.de> wrote:
> how can I check whether a directory is readable or not. Are there
> differences between unix and windows?

The Pythonic way would be to just do what you need to do (in this
case, presumably, read the directory) and catch the specific exception
(in this case, presumably, OSError).

    try:
        # Do whatever needs a readable directory
        normal_reading_stuff()

    except OSError, e:
        # Do whatever we need to when the directory is unreadable
        print "Unable to read stuff:", e.strerror

-- 
 \         "I got contacts, but I only need them when I read, so I got |
  `\                                      flip-ups."  -- Steven Wright |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list