title: Get the containing folder of a file
body: <p>I am trying to extract the containing folder of a file in Rust. Is there any way to go from a <code>String</code> to getting the containing folder? For example, the following code works, however it is messy:</p>
  <pre><code>let path = &quot;/path/to/file.txt&quot;;
  
  let mut path_arr: Vec&lt;&amp;str&gt; = path.split('/').collect();
  path_arr.pop();
  
  let new_string = path_arr.join(&quot;/&quot;);
  
  assert_eq!(&quot;/path/to&quot;, new_string);
  </code></pre>