Detecting symbolic links and pipes in Mono

試著忘記壹切 提交于 2019-12-06 02:31:58

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

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!