【发布时间】:2020-09-03 11:37:36
【问题描述】:
System.IO.Path 方法在组合两条路径时给了我一些非常奇怪的结果;
string Dir = "\\server1\\customers\\Test";
string path = "..\\..\\customers\\Test\\hello.pbt";
path = Path.Combine(Dir, path);
// path = "\\server1\\customers\\Test\\..\\..\\customers\\Test\\hello.pbt"
现在我想组合这些路径:
path = "\\server1\\customers\\Test\\hello.pbt" // aim
但是使用 Path.GetFullPath 方法,它不会按原样返回到服务器
path = Path.GetFullPath(path)
// path = "\\server1\\customers\\customers\\Test\\hello.pbt"
我已经尝试了Combining two relative paths with C#答案中描述的所有方法
【问题讨论】:
-
Combine 方法只是将第一个与第二个连接起来。实际上,结果并不奇怪,而是在意料之中。什么是“组合”的规则会导致预期的结果?
-
是的,我知道,但它应该倒退两次而不是一次!