In C#, How to obtain the target of a symbolic link (or Reparse Point)?
Posted
by Cheeso
on Stack Overflow
See other posts from Stack Overflow
or by Cheeso
Published on 2010-02-20T13:59:41Z
Indexed on
2010/03/12
1:57 UTC
Read the original article
Hit count: 836
In .NET, I think I can determine if a file is a symbolic link by calling System.IO.File.GetAttributes(), and checking for the ReparsePoint bit. like so:
var a = System.IO.File.GetAttributes(fileName);
if ((a & FileAttributes.ReparsePoint) != 0)
{
// it's a symlink
}
How can I obtain the target of the symbolic link, in this case?
ps: I know how to create a symbolic link. It requires P/Invoke:
[Interop.DllImport("kernel32.dll", EntryPoint="CreateSymbolicLinkW", CharSet=Interop.CharSet.Unicode)]
public static extern int CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, int dwFlags);
© Stack Overflow or respective owner