Skip to content

Instantly share code, notes, and snippets.

@CodyKochmann
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodyKochmann/cf186411fd97aa9aac3f to your computer and use it in GitHub Desktop.
Save CodyKochmann/cf186411fd97aa9aac3f to your computer and use it in GitHub Desktop.
python script to ensure there is a directory of that name in that path
def ensure_dir(dir_name,parent_dir,verbose=False):
# ensures there is a directory of that name in that path
# by: Cody Kochmann
# ex: trash_dir=ensure_dir("trash", script_dir)
def v_log(s):
if(verbose):
print(s)
from os import listdir, path, mkdir
dir_name=dir_name.replace("/", "")
if parent_dir[-1] != "/":
parent_dir+="/"
new_dir = parent_dir+dir_name
v_log(new_dir)
if path.isdir(new_dir) == False:
mkdir(new_dir)
else:
v_log("%s already exists" % (dir_name))
return(new_dir+"/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment