Skip to content

Instantly share code, notes, and snippets.

@ByoungInKim
Last active May 30, 2024 08:33
Show Gist options
  • Save ByoungInKim/03096da17ff645ae1c4caa2268b2ae9f to your computer and use it in GitHub Desktop.
Save ByoungInKim/03096da17ff645ae1c4caa2268b2ae9f to your computer and use it in GitHub Desktop.
python - create directory if path if it doesn`t exist for file write
import os
directory = '/home/kenny/gist'
if not os.path.exists(directory):
os.makedirs(directory)
@SebastianoX
Copy link

With pathlib:

from pathlib import Path

path_to_folder = Path("/home/kenny/gist")
path_to_folder.mkdir(exist_ok=True)

@neutrixs
Copy link

neutrixs commented Jun 5, 2021

thx

@jarvissilva937
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment