views:

114

answers:

3

Trying to figure out if a file is in a folder that has been subst'd or is located in a user folder using C#

+2  A: 

If Subst is run without parameters it produces a listing of all current substitutions. Get the list, check your directory against the list.

There is also the issue of mapping a volume to a directory. I have never attempted to detect these but the mount point directories do show up differently than regular directories so they must have a different attribute of some kind and that could be detected.

Loren Pechtel
+1  A: 

I think you have a few choices --

Via System.Management classes: http://briancaos.wordpress.com/2009/03/05/get-local-path-from-unc-path/

Or

Via P/Invoking this MAPI function: ScUNCFromLocalPath http://msdn.microsoft.com/en-us/library/cc842520.aspx

Bill
this looks promising, looking into it
petejamd
+1  A: 

I think you need to P/Invoke QueryDosDevice() for the drive letter. Subst drives will return a symbolic link, similar to \??\C:\blah. The \??\ prefix indicates it is substituted, the rest gives you the drive+directory.

Hans Passant
<a href="http://weblogs.asp.net/avnerk/archive/2006/06/04/Query-SUBST-information.aspx">Here's</a> a link to an example.
petejamd
Heh, good guess :)
Hans Passant