diff --git a/file/file_utils.py b/file/file_utils.py index a05a033..280e778 100644 --- a/file/file_utils.py +++ b/file/file_utils.py @@ -171,6 +171,27 @@ def path_split_all(p): return _pathsplit(p) +def path_prep(*paths): + """Like os.path.join, except that the directory part is created \ + on-the-fly as needed.""" + from os.path import dirname, isdir, join + path = join(*paths) + d = dirname(path) + mkdir_p(d) + return path + +def mkdir_p(name): + """A pure python implementation of my shell favorite `mkdir -p' command. + To conform to that command's behavior, we will not issue an error + if the file name exists and is a directory. + Returns 1 if new directories are made, returns -1 if nothing is done.""" + from os.path import isdir + if isdir(name): + return -1 + else: + os.makedirs(name) + return 1 + # - globbing