title: os.walk get directory names
body: <p>I have such file structure:</p>
  
  <pre><code>d:\temp\random1\index.html
  d:\temp\random2\index.html
  d:\temp\random3\index.html
  </code></pre>
  
  <p>and I want to get paths to list in python. So the output would be: </p>
  
  <pre><code>files = ['path': 'd:\temp\random1\index.html', 'directory': 'random1']
  </code></pre>
  
  <p>I am using such code:</p>
  
  <pre><code>files = []
  for dirpath, dirnames, filenames in os.walk('D:\\temp'):
      for fname in filenames:
          if fname.endswith(".md"):
              path = os.path.join(dirpath,fname)
              files.append({'path':path,'directory': dirpath})
  </code></pre>
  
  <p>but I cannot figure out how to get <em>directory</em> values.All I get with this code is:</p>
  
  <pre><code>files = ['path': 'd:\temp\random1\index.html', 'directory': 'd:\temp\random1\']
  </code></pre>
  
  <p>How to get the directory without some dirty hacks?</p>