5

I have a situation where a user can specify two separate pathnames, and I need to check whether one pathname is "inside" the other one. I can do this if both pathnames are UNC, or both are drive-letter-based, but what if they are mixed?

Can you "normalise" a path such as "C:\Program Files" to "\\[this computer name]\C\Program Files"? Obviously, I can't go the other way, as a network folder in UNC format may not have a corresponding drive letter mapped to it.

rossmcm
  • 5,493
  • 10
  • 55
  • 118

1 Answers1

6

Have a look at ExpandUNCFileName function.

kludg
  • 27,213
  • 5
  • 67
  • 118
  • +1 Also the [WNetGetUniversalName](http://msdn.microsoft.com/en-us/library/windows/desktop/aa385474%28v=vs.85%29.aspx) function can help too. – RRUZ May 05 '12 at 05:05
  • (@RRUZ, isn't `ExpandUNCFileName` a wrapper for `WNetGetUniversalName`, or can you learn more with that call?) I had erroneously thought that `ExpandUNCFilename` didn't work in all cases, but a bit of more thorough testing shows that if `ExpandUNCFileName` doesn't return a name starting with ` \\ ` its because it's a local drive. So one path can't be inside the other if either of their `ExpandUNCFileName`'d versions start with a drive letter. – rossmcm May 05 '12 at 06:03
  • Yes the `ExpandUNCFileName ` calls the `WNetGetUniversalName` function but with the `UNIVERSAL_NAME_INFO_LEVEL` flag, you can use this function with the `REMOTE_NAME_INFO_LEVEL` value too. So you can build a more complete solution using directly the NetGetUniversalName function. – RRUZ May 05 '12 at 06:07