Created
April 19, 2010 13:55
-
-
Save luispedro/371067 to your computer and use it in GitHub Desktop.
create directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import path, mkdir, errno | |
def create_directories(dname): | |
''' | |
create_directories(dname) | |
Recursively create directories. | |
''' | |
if dname.endswith('/'): dname = dname[:-1] | |
head, tail = path.split(dname) | |
if head: create_directories(head) | |
try: | |
mkdir(dname) | |
except OSError, e: | |
if e.errno != errno.EEXIST: | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment