title: How to get the parent directory of a path string
body: <p>I want to do the same thing as the bash <code>dirname</code> command or python <code>os.path.split()[0]</code> in vimscript for any path string (not necessarily the path of the current file).</p>
  
  <p>Sample desired behaviour:</p>
  
  <ul>
  <li><code>/a/b/</code> -> <code>/a</code></li>
  <li><code>/a/b</code> -> <code>/a</code></li>
  </ul>
  
  <p>I have tried <code>fnamemodify()</code> but to me its output seems to depend on whether dirs exist or not:</p>
  
  <pre><code>:ec fnamemodify( '/usr/idontexist', ':p:h')
  </code></pre>
  
  <p>gives:</p>
  
  <pre><code>/usr
  </code></pre>
  
  <p>which is good, but:</p>
  
  <pre><code>:ec fnamemodify( '/usr/bin', ':p:h')
  </code></pre>
  
  <p>gives:</p>
  
  <pre><code>/usr/bin
  </code></pre>
  
  <p>which is not what I want, and I can't figure out what it is doing.</p>
  
  <p>I hope to find a cross platform solution.</p>