title: Formatting a Linux path in C#
body: <p>So I am making a file browser using the WinSCP library in C#. The files and folders from the remote server are loaded into a ListView, and I have an event on the ListView_DoubleClick event that will go and get the files for that folder. However my problem is, the "CurrentPath" returned from WinSCP is built like so;
  "/eddata/T". Now if a user goes back up a directory, the path returned is "/eddata/T/../". If the user then goes into another folder called "Bob", the path now looks like; "/eddata/T/../Bob".</p>
  
  <p>I want a way so I can display the current path in a user friendly way. So when a user is in the directory; "/eddata/T/" and they go up a level, a label should tell them they are in; "/eddata/";</p>
  
  <p>This is my attempt but isn't working as expected, it doesn't deal the event where a user goes back up two directories at the same time;</p>
  
  <pre><code>private string FormatPathString(string input)
  {
  
      String working = input;
  
      bool replacement = true;
      while (replacement)
      {
          string[] splits = working.Split('/');
          splits = splits.AsEnumerable().Where(x =&gt; x != String.Empty).ToArray();
  
          int? found_index = null;
  
          for (int i = splits.Count() - 1; i &gt; 0; i--)
          {
              if (splits[i] == "..")
              {
                  found_index = i;
                  break;
              }
          }
  
          if (found_index.HasValue)
          {
              replacement = true;
              splits = splits.Where((val, idx) =&gt; (idx != found_index) &amp;&amp; (idx != found_index - 1)).ToArray();
              working = String.Join("/", splits);
          }
          else
          {
              replacement = false;
          }
  
      }
  
      return working;
  }
  </code></pre>