Send As SMS

7/18/2006

create a directory in python

assuming you're running some *nix (including mac os x), here's how to create a directory from within a python script. note that we need to check if the directory exists before creating a directory (if you try and overwrite a directory, python will throw an error).

here goes:

import os;
...
dirname = "my_dir_name"
if not os.path.isdir("./" + dirname + "/"):
os.mkdir("./" + dirname + "/")


note that the last line needs to be indented (silly blogger won't let me indent that line!)


0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home

My blog has moved! Redirecting...

You should be automatically redirected. If not, visit http://stinkpot.afraid.org:8080/tricks/ and update your bookmarks.