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.
Try makedirs() instead of makedir(). It will work.
E.g. To create foo/bar/bar1,
>>> import os>>> os.makedirs('foo/bar/bar1')