How can I check if a dir exists ?
check if dir exists
Collapse
This topic is closed.
X
X
-
Geiregat Jonas -
Abe Frohnman
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
-
Skip Montanaro
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
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
Comment