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)


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.