在.NET中,如何获取一个符号链接(或重新分析点)的目标是什么? [英] In .NET, How to obtain the target of a symbolic link (or Reparse Point)?

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

问题描述

在.NET中,我想我能确定一个文件是通过调用System.IO.File.GetAttributes(),并检查了ReparsePoint位的符号链接。像这样:

  VAR一个= System.IO.File.GetAttributes(文件名);
如果((A&安培;!FileAttributes.ReparsePoint)= 0)
{
    //这是一个符号链接
}
 

我怎样才能获得的符号链接的目标,在这种情况下?


PS:我知道如何为创建的符号链接。它需要的P / Invoke:

  [Interop.DllImport(KERNEL32.DLL,入口点=CreateSymbolicLinkW,字符集= Interop.CharSet.Uni code)
公共静态外部INT CreateSymbolicLink(字符串lpSymlinkFileName,串lpTargetFileName,INT的dwFlags);
 

解决方案

您必须使用的DeviceIoControl(),并发送FSCTL_GET_REPARSE_POINT控制code。在P / Invoke的和API的使用细节都相当坚韧不拔,但是它<一个href="http://www.google.com/#hl=en&q=c%23+FSCTL_GET_REPARSE_POINT&aq=f&aqi=&oq=&fp=d95f0d161f018361"相对=nofollow>谷歌真的很好。

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

解决方案

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天全站免登陆