title: Elegant way to make all dirs in a path
body: <p>Here are four paths:</p>
  
  <pre><code>p1=r'\foo\bar\foobar.txt'
  p2=r'\foo\bar\foo\foo\foobar.txt'
  p3=r'\foo\bar\foo\foo2\foobar.txt'
  p4=r'\foo2\bar\foo\foo\foobar.txt'
  </code></pre>
  
  <p>The directories may or may not exist on a drive. What would be the most elegant way to create the directories in each path?</p>
  
  <p>I was thinking about using <code>os.path.split()</code> in a loop, and checking for a dir with <code>os.path.exists</code>, but I don't know it there's a better approach.</p>