Python How to Safely Create a Nested Directory
import os
os.getcwd()
if not os.path.exists(dir):
os.mkdir(dir)
import os
os.makedirs(path, exist_ok=True)
creates the directory and does not raise an exception if the directory already exists.
import pathlib
pathlib.Path(dir).mkdir(parents=True, exist_ok=True)
import errno
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise