title: Normalize path expressions for virtual file system
body: <p>Say you have for instance a <a href="https://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive%28v=vs.110%29.aspx" rel="nofollow"><code>ZipArchive</code></a>. Using this class, one handles a file system that is not attached to the real file system.</p>
  
  <p>Say the archive has the following structure:</p>
  
  <pre><code>.
  ├── Foo
  │   └── File1
  └── Bar
      └── File2
  </code></pre>
  
  <p>Now one can read <code>File1</code>. If <code>File1</code> contains a relative reference to <code>File2</code>, it is written as <code>../Bar/File2</code>.</p>
  
  <p>The question is how one can combine the directory of <code>File1</code> (<code>Foo/</code>) with the path <code>../Bar/File2</code> such that the result is <code>Bar/File2</code> (the <code>ZipArchive</code> can't handle combinations of relative with absolute paths).</p>
  
  <p>Tried solutions with (<code>dir</code> and <code>rel</code>):</p>
  
  <ul>
  <li><a href="https://msdn.microsoft.com/en-us/library/system.io.path.combine%28v=vs.110%29.aspx" rel="nofollow"><code>Path.Combine</code></a><code>(dir,rel)</code> only places a <code>/</code> between the two, thus the entry can't be resolved;</li>
  <li><code>new</code><a href="https://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.fullname%28v=vs.110%29.aspx" rel="nofollow"><code>DirectoryInfo</code></a><code>(Path.Combine(dir,rel)).FullName</code> generates a part with the current directory (<code>cd</code>) included; and</li>
  <li><a href="https://msdn.microsoft.com/en-us/library/system.io.path.getfullpath%28v=vs.110%29.aspx" rel="nofollow"><code>Path.GetFullPath</code></a><code>(Path.Combine(dir,rel)).FullName</code> does the same</li>
  </ul>
  
  <p>How can one normalize such relative paths? One can of course write a normalizer oneself, but the odds are high the algorithm will lack some parts of the specifications.</p>