Create directories needed to write a file


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



Copy this code and paste it in your HTML
  1. def ensure_dir(f):
  2. d = os.path.dirname(f)
  3. if not os.path.exists(d):
  4. os.makedirs(d)

URL: http://stackoverflow.com/questions/273192/python-best-way-to-create-directory-if-it-doesnt-exist-for-file-write/273679

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.