Posted By

magicrebirth on 11/04/10


Tagged

file path dir os sys


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Desoxena


Creating directories programmatically


 / Published in: Python
 

save as a file and run....

  1. import sys
  2. import os
  3.  
  4.  
  5. def ensure_dir(f):
  6. d = os.path.dirname(f)
  7. if not os.path.exists(d):
  8. os.makedirs(d)
  9.  
  10.  
  11. def main():
  12. for x in range(150):
  13. # change this as needed
  14. filename = "/Users/mac/Desktop/temp/" + str(x+1) + "/"
  15. ensure_dir(filename)
  16.  
  17.  
  18. if __name__ == '__main__':
  19. main()

Report this snippet  

You need to login to post a comment.