title: Find root of path
body: <p>I have a path:</p>
  
  <pre><code>path = foo/bar/baz
  </code></pre>
  
  <p>and I would like to determine what the base is. In this example it should return <em>"foo"</em>.  </p>
  
  <p>There are a few ways I have tried:</p>
  
  <pre><code>root = re.search('(.+?)/(.+)', path).group(1)
  
  paths = path.split('/')[0]
  root = paths[0] if paths[0] or len(paths) &lt;= 1 else '/'.join(paths[0:2])
  
  def rootname(path):
    head,tail = os.path.split(path)
    if head != '':
     return rootname(head)
    else:
     return path
  root = rootname(path)
  </code></pre>
  
  <p>Is there a more 'Pythonic' way to access the root directory?</p>
  
  <p>i.e.</p>
  
  <pre><code>root = os.path.''rootname''(path)
  </code></pre>