Dus*_*vis 33
检查DirectoryInfo.Parent是否为null
DirectoryInfo d = new DirectoryInfo("");
if(d.Parent == null) { IsRoot = true; }
Run Code Online (Sandbox Code Playgroud)
您也可以使用DirectoryInfo.Root获取根目录;
试试这个:
if (Path.GetPathRoot(location) == location) {...}
Run Code Online (Sandbox Code Playgroud)
它比检查Parent属性要复杂得多.
一种方法是看是否GetVolumeNameForVolumeMountPoint成功.
当然,这对网络路径不起作用,确定网络驱动器是否代表分区的根目录可能无法远程实现.
| 归档时间: |
|
| 查看次数: |
17143 次 |
| 最近记录: |