creates missing directories for the given path and returns a normalized absolute version of the path. - if the given path already exists in the filesystem the filesystem is not modified. - otherwise makepath creates directories along the given path using the dirname()
(path)
| 1 | #!/usr/bin/env python |
| 2 | |
| 3 | def makepath(path): |
| 4 | |
| 5 | """ creates missing directories for the given path and |
| 6 | returns a normalized absolute version of the path. |
| 7 | |
| 8 | - if the given path already exists in the filesystem |
| 9 | the filesystem is not modified. |
| 10 | |
| 11 | - otherwise makepath creates directories along the given path |
| 12 | using the dirname() of the path. You may append |
| 13 | a '/' to the path if you want it to be a directory path. |
| 14 | |
| 15 | from holger@trillke.net 2002/03/18 |
| 16 | """ |
| 17 | |
| 18 | from os import makedirs |
| 19 | from os.path import normpath,dirname,exists,abspath |
| 20 | |
| 21 | dpath = normpath(dirname(path)) |
| 22 | if not exists(dpath): makedirs(dpath) |
| 23 | return normpath(abspath(path)) |
| 24 | |
| 25 | # |
| 26 | # |