+1 vote
in Programming Languages by (8.1k points)

I want to create subfolders inside a folder that does not exist. E.g. foo/bar/bar1

When I use mkdir('foo'), it creates the directory 'foo'. But when I use mkdir('foo/bar'), it gives error.

1 Answer

0 votes
by (15.9k points)

Try makedirs() instead of makedir(). It will work.

E.g. To create foo/bar/bar1,

>>> import os
>>> os.makedirs('foo/bar/bar1')

...