0 points

Create a nested directory in Python 3.5+


Posted by @bravocoder #python

import pathlib
pathlib.Path('/my/directory').mkdir(parents=True, exist_ok=True) 
content_copy Copy

pathlib.Path.mkdir recursively creates the directory and does not raise an exception if the directory already exists. If you don't need or want the parents to be created, skip the parents argument.