
I had to implement this code frequently, and I really don’t like it, so I’m leaving it here.
import os
import shutil
def create_directory(
path: str,
recreate: bool=False
):
if os.path.exists(path):
if recreate:
shutil.rmtree(path)
os.makedirs(path)
else:
os.makedirs(path)