为什么“Path.GetFullPath”在用网络路径上的相关元素解析路径时表现异常? 试试这个小例子并比较结果:
using System;
using System.IO;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
Console.WriteLine(Path.GetFullPath(@"C:\Stay\Elim1\Elim2\..\..\SomeFolder")); // yields C:\Stay\SomeFolder
Console.WriteLine(Path.GetFullPath(@"\\Stay\Elim1\Elim2\..\..\SomeFolder")); // yields \\Stay\Elim1\SomeFolder ???
}
}
}
这可能是一个错误,或者其中可能有某种意义,但我不明白。
(所有路径甚至部分路径都不存在于我的机器上,因此它只是一个字符串操作)
最佳答案
当您使用网络路径时,路径的第二部分是共享名而不是目录。
Console.WriteLine(Path.GetFullPath(@"C:\SomeDir\Dir1\Dir2\..\..\SomeFolder"));
C:\SomeDir\SomeFolder
Console.WriteLine(Path.GetFullPath(@"\\Server\ShareName\Dir1\Dir2\..\..\SomeFolder"));
\Server\ShareName\SomeFolder
关于c# - "Path.GetFullPath"和网络路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17838970/