4

Why does "Path.GetFullPath" behave strange when resolving paths with relative elements on a network path? Try this small example and compare the results:

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 ???
        }
    }
}

It might be a bug or there might be some sense in it, but I don't get it.

(None of the pathes or even parts of it them really exist on my machine, so its merely a string operation)

4

1 回答 1

8

当您使用网络路径时,路径的第二部分是共享名而不是目录。

Console.WriteLine(Path.GetFullPath(@"C:\SomeDir\Dir1\Dir2\..\..\SomeFolder"));  

C:\SomeDir\SomeFolder

Console.WriteLine(Path.GetFullPath(@"\\Server\ShareName\Dir1\Dir2\..\..\SomeFolder"));

\Server\ShareName\SomeFolder

于 2013-07-24T15:56:06.777 回答