2017-07-19 56 views
0

我有以下功能:PathRelativePathTo正在改變的unicode charactrs以ASCII

public static string GetRelativePath(string fromPath, string toPath) 
    { 
     // we also tried the Uri solution but that does not return .. when you need to traverse 
     // one up only 
     // uri1 = "bla\foo" 
     // uri2 = "bla\bar" 
     // uri1.MakeRelaitveto(uri2) != "..\bar" 
     var path = new StringBuilder(260); // MAX_PATH 
     if (PathRelativePathTo(
      path, 
      fromPath.Replace('/', '\\'), 
      FILE_ATTRIBUTE_DIRECTORY, 
      toPath.Replace('/', '\\'), 
      FILE_ATTRIBUTE_DIRECTORY) == 0) 
     { 
      return toPath; 
     } 

     return path.ToString().Replace('\\', Path.DirectorySeparatorChar); 
    } 

    [DllImport("shlwapi.dll", SetLastError = true)] 
    private static extern int PathRelativePathTo(
     StringBuilder pszPath, string pszFrom, int dwAttrFrom, string pszTo, int dwAttrTo); 
} 

我與下面的測試用例撥打:

GetPathRelativeTo("C:\\somεpath", "C:\\anothεrpath").Shouldbe("..\\anothεrpath") 

而是它返回..\\anotherpath。請注意,ε已被替換爲e

我嘗試過使用PathRelativePathToW,但是它的工作更少(其他測試用例失敗)。

有誰知道是怎麼回事,我怎麼能防止更換炭的?

回答