Windows – How to resolve a canonical filename in Windows


If I have a string that resolves to a file path in Windows, is there an accepted way to get a canonical form of the file name?

For example, I'd like to know whether




actually point to the same file or not, and store the canonical form of the path in my application.

Note that simple string comparisons won't work, nor will any RegEx magic. Remember that we have things like NTFS reparse points to deal with since Windows 2000 and the new Libraries structure in Windows 7.

Best Solution

Short answer: not really.

There is no simple way to get the canonical name of a file on Windows. Local files can be available via reparse points, via SUBST. Do you want to deal with NTFS junctions? Windows shortcuts? What about \\?\-escaped filenames

Remote files can be available via mapped drive letter or via UNC. Is that the UNC to the origin server? Are you using DFS? Is the server using reparse points, etc.? Is the server available by more than one name? What about the IP address? Does it have more than one IP address?

So, if you're looking for something like the inode number on Windows, it ain't there. See, for example, this page.