Python pathlib make directories if they don’t exist
Yes, that is Path.mkdir
:
pathlib.Path('/tmp/sub1/sub2').mkdir(parents=True, exist_ok=True)
This gives additional control for the case that the path is already there:
path = Path.cwd() / 'new' / "hi" / "there"
try:
path.mkdir(parents=True, exist_ok=False)
except FileExistsError:
print("Folder is already there")
else:
print("Folder was created")