title: Get folder name of the file in Python
body: <p>In Python what command should I use to get the name of the folder which contains the file I'm working with?</p>
  <p><code>&quot;C:\folder1\folder2\filename.xml&quot;</code></p>
  <p>Here <code>&quot;folder2&quot;</code> is what I want to get.</p>
  <p>The only thing I've come up with is to use <code>os.path.split</code> twice:</p>
  <pre class="lang-py prettyprint-override"><code>folderName = os.path.split(os.path.split(&quot;C:\folder1\folder2\filename.xml&quot;)[0])[1]
  </code></pre>
  <p>Is there any better way to do it?</p>