Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > check if dir exists

Reply
Thread Tools

check if dir exists

 
 
Geiregat Jonas
Guest
Posts: n/a
 
      07-09-2003
How can I check if a dir exists ?
 
Reply With Quote
 
 
 
 
Skip Montanaro
Guest
Posts: n/a
 
      07-09-2003

Geiregat> How can I check if a dir exists ?

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

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

False

Skip

 
Reply With Quote
 
 
 
 
Abe Frohnman
Guest
Posts: n/a
 
      07-09-2003
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

 
Reply With Quote
 
Dave Reed
Guest
Posts: n/a
 
      07-09-2003
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if a directory exists? folder.exists() does not work! Ulf Meinhardt Java 8 08-28-2009 12:26 PM
How to check if all *.jars in my CLASSPATH really exists? Automatic check (not manual) possible? Jason Stacy Java 2 04-27-2008 08:14 AM
Behaviour of Dir.glob("**/b") and Dir.glob("*/b") for symlinks Matthew Denner Ruby 1 08-04-2006 03:42 PM
Sub Dir, Virtual dir, what do I use? =?Utf-8?B?UnVkeQ==?= ASP .Net 0 06-12-2005 08:25 PM
Re: check if dir exists Bob Gailer Python 0 07-09-2003 07:16 PM



Advertisments