check whether directory is readable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eels

    #1

    check whether directory is readable

    Hello,
    how can I check whether a directory is readable or not. Are there
    differences between unix and windows?
    Thank you for your hints, Eels

  • Jonas Geiregat

    #2
    Re: check whether directory is readable

    eels wrote:[color=blue]
    > Hello,
    > how can I check whether a directory is readable or not. Are there
    > differences between unix and windows?[/color]

    As far as I know there aren't any differences,

    code:

    import os
    if access("/root", os.R_OK):
    print "You are able to read the /root dir"

    Comment

    • Ben Finney

      #3
      Re: check whether directory is readable

      eels <eels@nikocity. de> wrote:[color=blue]
      > how can I check whether a directory is readable or not. Are there
      > differences between unix and windows?[/color]

      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

      Comment

      Working...