check if dir exists

Discussion in 'Python' started by Geiregat Jonas, Jul 9, 2003.

  1. How can I check if a dir exists ?
    Geiregat Jonas, Jul 9, 2003
    #1
    1. Advertising

  2. Geiregat> How can I check if a dir exists ?

    >>> import os
    >>> print os.path.isdir("/tmp")

    True
    >>> print os.path.isdir("/foo")

    False

    Skip
    Skip Montanaro, Jul 9, 2003
    #2
    1. Advertising

  3. Geiregat Jonas

    Abe Frohnman Guest

    Geiregat Jonas wrote:

    > How can I check if a dir exists ?


    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
    Abe Frohnman, Jul 9, 2003
    #3
  4. Geiregat Jonas

    Dave Reed Guest

    On Wednesday 09 July 2003 15:01, Geiregat Jonas wrote:
    > How can I check if a dir exists ?
    > --


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

    Dave
    Dave Reed, Jul 9, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    421
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. Bob Gailer

    Re: check if dir exists

    Bob Gailer, Jul 9, 2003, in forum: Python
    Replies:
    0
    Views:
    341
    Bob Gailer
    Jul 9, 2003
  3. Jason Stacy
    Replies:
    2
    Views:
    4,673
    Roedy Green
    Apr 27, 2008
  4. Ulf Meinhardt
    Replies:
    8
    Views:
    6,138
  5. Matthew Denner
    Replies:
    1
    Views:
    176
Loading...

Share This Page