Skip to content

Instantly share code, notes, and snippets.

@luispedro
Created April 19, 2010 13:55
Show Gist options
  • Save luispedro/371067 to your computer and use it in GitHub Desktop.
Save luispedro/371067 to your computer and use it in GitHub Desktop.
create directories
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