Skip to content

Instantly share code, notes, and snippets.

@William-Hill
Created January 22, 2018 07:56
Show Gist options
  • Save William-Hill/f5fa6b78b7de5ef86ec0079f5c32b65d to your computer and use it in GitHub Desktop.
Save William-Hill/f5fa6b78b7de5ef86ec0079f5c32b65d to your computer and use it in GitHub Desktop.
Create directory with parent directories as needed; Mimics mkdir -p
'''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