Last active
May 30, 2024 08:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
directory = '/home/kenny/gist' | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
Thank you!
Nice, thanks!
Thanks!
PS: You've a typo (directroy --> directory)
Thanks!
os.makedirs(directory, exist_ok=True)
os.makedirs(directory, exist_ok=True)
This syntax is actually in vs code intellisense. The second parameter is in case that exists returned true? which should be like if (os.....)
With pathlib:
from pathlib import Path
path_to_folder = Path("/home/kenny/gist")
path_to_folder.mkdir(exist_ok=True)
thx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!