/Demo/scripts/makedir.py

http://unladen-swallow.googlecode.com/ · Python · 21 lines · 11 code · 5 blank · 5 comment · 4 complexity · 62b6859e2e5410b5e20541f7b7da075d MD5 · raw file

  1. #! /usr/bin/env python
  2. # Like mkdir, but also make intermediate directories if necessary.
  3. # It is not an error if the given directory already exists (as long
  4. # as it is a directory).
  5. # Errors are not treated specially -- you just get a Python exception.
  6. import sys, os
  7. def main():
  8. for p in sys.argv[1:]:
  9. makedirs(p)
  10. def makedirs(p):
  11. if p and not os.path.isdir(p):
  12. head, tail = os.path.split(p)
  13. makedirs(head)
  14. os.mkdir(p, 0777)
  15. if __name__ == "__main__":
  16. main()