tags:

views:

48

answers:

2

if b/c/ does not exist in ./a/b/c , shutil.copy("./blah.txt", "./a/b/c/blah.txt") will complain that the destination does not exist.

how can i create the path at the same time?

+3  A: 

Use os.makedirs to create the directory tree.

Philipp
A: 

I use something similar to this to check if the directory exists before doing things with it.

if not os.path.exists('a/b/c/'):
    os.mkdir('a/b/c')
thegrinner