Note that there are some explanatory texts on larger screens.

plurals
  1. POVerifying path equality with .Net
    primarykey
    data
    text
    <p>What is the best way to compare two paths in .Net to figure out if they point to the same file or directory?</p> <ol> <li><p>How would one verify that these are the same:</p> <pre><code>c:\Some Dir\SOME FILE.XXX C:\\\SOME DIR\some file.xxx </code></pre></li> <li><p>Even better: is there a way to verify that these paths point to the same file on some network drive:</p> <pre><code>h:\Some File.xxx \\Some Host\Some Share\Some File.xxx </code></pre></li> </ol> <p><strong>UPDATE:</strong></p> <p>Kent Boogaart has answered my first question correctly; but I`m still curious to see if there is a solution to my second question about comparing paths of files and directories on a network drive.</p> <p><strong>UPDATE 2 (combined answers for my two questions):</strong></p> <p><strong>Question 1:</strong> local and/or network files and directories</p> <pre><code>c:\Some Dir\SOME FILE.XXX C:\\\SOME DIR\some file.xxx </code></pre> <p><strong>Answer:</strong> use <code>System.IO.Path.GetFullPath</code> as exemplified with:</p> <pre><code>var path1 = Path.GetFullPath(@"c:\Some Dir\SOME FILE.XXX"); var path2 = Path.GetFullPath(@"C:\\\SOME DIR\subdir\..\some file.xxx"); // outputs true Console.WriteLine("{0} == {1} ? {2}", path1, path2, string.Equals(path1, path2, StringComparison.OrdinalIgnoreCase)); </code></pre> <p><strong>Question 2:</strong> local and/or network files and directories</p> <p><strong>Answer:</strong> Use the GetPath method as posted on <a href="http://briancaos.wordpress.com/2009/03/05/get-local-path-from-unc-path/" rel="noreferrer">http://briancaos.wordpress.com/2009/03/05/get-local-path-from-unc-path/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload