0
Q:

python make directory if not exists

import os
if not os.path.exists('my_folder'):
    os.makedirs('my_folder')
19
from pathlib import Path
Path("/my/directory").mkdir(parents=True, exist_ok=True)    #python 3.5 above
3
try:
    os.makedirs("path/to/directory")
except FileExistsError:
    # directory already exists
    pass
0

New to Communities?

Join the community