Computer >> Computer tutorials >  >> Programming >> Python

How does mkdir -p work in Python?


mkdir -p is used to allow creating recursive directory making even if parent exists. To create a directory recursively, provide the path you want to create to the os.makedirs(path). To create a directory recusrively, you need to specify exists_ok as True to allow existing folders.

>>> import os
>>> os.makedirs('my_folder/another/folder', exists_ok=True)