Skip to content
Demo user edited this page Dec 15, 2014 · 13 revisions

eeeeeeeeeeee A simple way to ensure all subdirectories exist:

def ensure_dirs_exists(filenames):
subdirs = {os.path.dirname(s) for s in filenames}
subdirs = [ s for s in subdirs if s != '' ]
subdirs.sort(key=len)
for s in subdirs:
        if not os.path.exists(s):
                os.mkdir(s)

How about some non ascii string like 'buen día ñoño !'

Oh, ^ looks good.

Test.

Clone this wiki locally