60

This works:

mkdir('folder')

but this doesn't

mkdir('folder/subfolder')

error:

WindowsError: [Error 3] The system cannot find the path specified: 'folder/subfolder'
b7875787
  • 601
  • 1
  • 5
  • 3

3 Answers3

111

Try os.makedirs instead, if you want to create a tree of directories in one call.

Matthew Iselin
  • 10,124
  • 4
  • 48
  • 60
33

I tried the above on Linux using Python 2.6.6, but had to ensure that the string ended with a '/' (or '\', on Windows). E.g.

os.makedirs('folder/subfolder/')

Otherwise only 'folder' was created.

stevej
  • 531
  • 5
  • 4
22

I think you want the os.makedirs() function, which can create intermediate directories.

dcrosta
  • 24,905
  • 8
  • 68
  • 82