在Mono中检测符号链接和管道 [英] Detecting symbolic links and pipes in Mono

查看:96
本文介绍了在Mono中检测符号链接和管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用C#和Mono区分特殊文件,例如符号链接和管道?

Is there a way to distinguish special files like symbolic links and pipes using C# and Mono?

该应用程序是一种多平台备份工具,因此我想避免使用互操作库或"C" dll,而是寻找一种直接的托管代码解决方案.

The application is a multi-platform backup tool, so I want to avoid using interop libraries or 'C' dll's and look for a straight managed code solution.

推荐答案

深入研究之后,我找到了解决方案.

After digging around some more, I've found a solution.

在项目中添加对 Mono.Posix 的引用可以访问某些Unix文件系统属性.

Adding a reference to Mono.Posix to a project gives access to some of the Unix file system attributes.

Mono.Unix.UnixSymbolicLinkInfo i = new Mono.Unix.UnixSymbolicLinkInfo( path );
switch( i.FileType )
{
   case FileTypes.SymbolicLink:
   case FileTypes.Fifo:
   case FileTypes.Socket:
   case FileTypes.BlockDevice:
   case FileTypes.CharacterDevice:
   case FileTypes.Directory:
   case FileTypes.RegularFile:
}

上面的代码有助于识别一系列特殊文件.

The above code helps identify a range of special files.

使用 UnixSymbolicLinkInfo 很重要,因为 UnixFileInfo UnixDirectoryInfo 在测试之前解决符号链接.

Using UnixSymbolicLinkInfo is important because both UnixFileInfo and UnixDirectoryInfo resolve the symbolic link prior to testing.

这篇关于在Mono中检测符号链接和管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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