[英]PathRelativePathTo is transforming unicode charactrs to 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
但是效果更差(其他測試用例失敗)。
有誰知道發生了什么事以及如何防止替換char?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.