Creating directories programmatically


/ Published in: Python
Save to your folder(s)

save as a file and run....


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.