Created
January 22, 2018 07:56
-
-
Save William-Hill/f5fa6b78b7de5ef86ec0079f5c32b65d to your computer and use it in GitHub Desktop.
Create directory with parent directories as needed; Mimics mkdir -p
This file contains hidden or 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
'''Makes a directory; no exception if directory already exists, make parent directories as needed''' | |
def mkdir_p(path, mode = 0777): | |
try: | |
os.makedirs(path, mode) | |
except OSError as exc: # Python >2.5 | |
if exc.errno == errno.EEXIST and os.path.isdir(path): | |
print("%s already exists.", path) | |
else: | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment