如何使用.Net获取符号链接(或重新解析点)的目标? [英] How to obtain the target of a symbolic link (or Reparse Point) using .Net?

查看:100
本文介绍了如何使用.Net获取符号链接(或重新解析点)的目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET中,我认为可以通过调用System.IO.File.GetAttributes()并检查ReparsePoint位来确定文件是否为符号链接。像这样:

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:我知道如何创建符号链接。它需要P / Invoke:

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); 


推荐答案

您必须使用DeviceIoControl()并发送FSCTL_GET_REPARSE_POINT控制代码。 P / Invoke和API使用情况的详细信息很严格,但是 Google真的很好

You have to use DeviceIoControl() and send the FSCTL_GET_REPARSE_POINT control code. The P/Invoke and API usage details are quite gritty, but it Googles really well.

这篇关于如何使用.Net获取符号链接(或重新解析点)的目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆