Last active
January 16, 2018 05:42
-
-
Save ipan/20652efe2e1eab0570306e37810076c2 to your computer and use it in GitHub Desktop.
python: mkdir -p #unix
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
""" | |
For Python ≥ 3.2, os.makedirs has an optional third argument exist_ok that, when true, enables the mkdir -p functionality -- unless mode is provided and the existing directory has different permissions than the intended ones; in that case, OSError is raised as previously. | |
""" | |
import errno | |
import os | |
def mkdir_p(path): | |
try: | |
os.makedirs(path) | |
except OSError as exc: # Python >2.5 | |
if exc.errno == errno.EEXIST and os.path.isdir(path): | |
pass | |
else: | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment