title: C# create file with same name as folder name, with extension
body: <p>Suppose I have a folder called <code>test</code>.<br>
  Now I pass that folder into a program and it will output a file called <code>test.xyz</code> in the same directory that contains the target folder.</p>
  
  <p>The general logic I'm using is something like</p>
  
  <pre><code>string outDir = Path.GetDirectoryName(path);
  string outName = Path.GetFileName(path).TrimEnd("\\".ToCharArray()) + ".xyz";
  string outFile = Path.Combine(outDir, outName);
  </code></pre>
  
  <p>Which works, but it seems kind of excessive to perform so many operations just to build my new filename.</p>
  
  <p>1: Can I reduce the number of Path calls to achieve my result?<br>
  2: Can I do something about the second line to avoid trimming and also avoid using that add operation?</p>