Guido van Rossum | f06ee5f | 1996-11-27 19:52:01 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | b83ec8f | 1992-05-19 13:52:02 +0000 | [diff] [blame] | 2 | |
| 3 | # Like mkdir, but also make intermediate directories if necessary. |
| 4 | # It is not an error if the given directory already exists (as long |
| 5 | # as it is a directory). |
| 6 | # Errors are not treated specially -- you just get a Python exception. |
| 7 | |
| 8 | import sys, os |
| 9 | |
| 10 | def main(): |
Tim Peters | e6ddc8b | 2004-07-18 05:56:09 +0000 | [diff] [blame] | 11 | for p in sys.argv[1:]: |
| 12 | makedirs(p) |
Guido van Rossum | b83ec8f | 1992-05-19 13:52:02 +0000 | [diff] [blame] | 13 | |
| 14 | def makedirs(p): |
Tim Peters | e6ddc8b | 2004-07-18 05:56:09 +0000 | [diff] [blame] | 15 | if p and not os.path.isdir(p): |
| 16 | head, tail = os.path.split(p) |
| 17 | makedirs(head) |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 18 | os.mkdir(p, 0o777) |
Guido van Rossum | b83ec8f | 1992-05-19 13:52:02 +0000 | [diff] [blame] | 19 | |
Johannes Gijsbers | 7a8c43e | 2004-09-11 16:34:35 +0000 | [diff] [blame] | 20 | if __name__ == "__main__": |
| 21 | main() |