views:

48

answers:

2

Say I have two directory paths:

C:\Shares\Apple\Orange

and

\\MACHINENAME\Apple\Orange

Is there a way to (programmatically) determine if they refer to the same directory? In general, can I determine whether two directory references are equivalent without comparing paths?

+1  A: 

Here's a way you can try. It may choke on some things. I haven't tested it.

  1. Call CreateFile() on each directory with FILE_FLAG_BACKUP_SEMANTICS.

  2. Call GetFileInformationByHandle() on both handles.

  3. Compare file index, volume serial number.

  4. Call GetVolumeInformationByHandle().

  5. Compare volume name.

You are right to say that comparing paths is a bad idea. Symbolic links, short names, and drive letter mappings get in your way that way.

asveikau
Thanks, this seems to do the trick!
marijne
A: 

No, not without explicit out-of-band cooperation from \\MACHINENAME. On Windows, the SMB protocol exposes no method to obtain a GUID uniquely identifying the underlying volume. The protocol doesn't even guarantee that you're looking at an actual volume.

MSalters