在Mono中检测符号链接和管道 [英] Detecting symbolic links and pipes in 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屋!