Skip to content
Demo user edited this page Jan 20, 2015 · 13 revisions

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