check if dir exists

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

    check if dir exists

    How can I check if a dir exists ?
  • Abe Frohnman

    #2
    Re: check if dir exists

    Geiregat Jonas wrote:
    [color=blue]
    > How can I check if a dir exists ?[/color]

    The os.path library has just what you're looking for. Use
    os.path.exists, like so:


    #!/usr/bin/python

    import os.path

    pathToFind = "/usr/bin/local"

    if os.path.exists( pathToFind):
    print "Path exists."
    else:
    print "Path does not exist."


    ~AF

    Comment

    • Skip Montanaro

      #3
      Re: check if dir exists


      Geiregat> How can I check if a dir exists ?
      [color=blue][color=green][color=darkred]
      >>> import os
      >>> print os.path.isdir("/tmp")[/color][/color][/color]
      True[color=blue][color=green][color=darkred]
      >>> print os.path.isdir("/foo")[/color][/color][/color]
      False

      Skip

      Comment

      • Dave Reed

        #4
        Re: check if dir exists

        On Wednesday 09 July 2003 15:01, Geiregat Jonas wrote:[color=blue]
        > How can I check if a dir exists ?
        > --[/color]

        See the os module, specifically the os.path functions I believe.

        Dave



        Comment

        Working...