[英]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.