detecting and creating directories

Angel Asencio asencio at mitre.org
Mon Oct 29 16:32:44 EST 2001


Excellent thanks!

Steve Holden wrote:

> "Angel Asencio" <asencio at mitre.org> wrote in ...
> > Greetings:
> >
> >   I found the module that has the command to make directories, but I
> > have not been lucky finding a way  to check for the existance of a
> > directory (so it is not there, I can create it).
> >
> > Any pointers?
> >
> You should also check that it really is a directory and not just a plain
> file! The following code is untested...
>
> import os
> path = "/usr/tmp/newdir"
> if os.path.exists(path):
>     if not os.path.isdir(path):
>         raise ValueError, "%s exists but is not a directory" % path
> else:
>     os.mkdir(path)
>
> regards
>  Steve
> --
> http://www.holdenweb.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: asencio.vcf
Type: text/x-vcard
Size: 337 bytes
Desc: Card for Angel Asencio
URL: <http://mail.python.org/pipermail/python-list/attachments/20011029/5bc1e244/attachment.vcf>


More information about the Python-list mailing list