Answer: There is no foolproof way in which you can compare to string base paths to determine if they point to the same file.
The main reason is that seemingly unrelated paths can point to the exact same file do to file system redirections (junctions, symbolic links, etc ...) . For example
"d:\temp\foo.txt"
"c:\othertemp\foo.txt"
These paths can potentially point to the same file. This case clearly eliminates any string comparison function as a basis for determining if two paths point to the same file.
The next level is comparing the OS file information. Open the file for two paths and compare the handle information. In windows this can be done with GetFileInformationByHandle. Lucian Wischik did an excellent post on this subject here.
There is still a problem with this approach though. It only works if the user account performing the check is able to open both files for reading. There are numerous items which can prevent a user from opening one or both files. Including but not limited to ...
- Lack of sufficient permissions to file
- Lack of sufficient permissions to a directory in the path of the file
- File system change which occurs between the opening of the first file and the second such as a network disconnection.
When you start looking at all of these problems you begin to understand why Windows does not provide a method to determine if two paths are the same. It's just not an easy/possible question to answer.