Skip to content

Instantly share code, notes, and snippets.

@lambdamusic
Created February 7, 2013 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambdamusic/4734307 to your computer and use it in GitHub Desktop.
Save lambdamusic/4734307 to your computer and use it in GitHub Desktop.
Python: Creating directories programmatically
import sys
import os
def ensure_dir(f):
d = os.path.dirname(f)
if not os.path.exists(d):
os.makedirs(d)
def main():
for x in range(150):
# change this as needed
filename = "/Users/mac/Desktop/temp/" + str(x+1) + "/"
ensure_dir(filename)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment