* wpylib.file.file_utils: added path_prep and mkdir_p.

master
Wirawan Purwanto 10 years ago
parent b043fb3cdf
commit 1e56bb95eb
  1. 21
      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

Loading…
Cancel
Save