我正在尝试使用Path.Combine
将Windows路径与相对路径连接起来。
但是,Path.Combine(@"C:\blah",@"..\bling")
返回C:\blah\..\bling
而不是C:\bling\
。
有谁知道如何在不编写我自己的相对路径解析器的情况下做到这一点(这应该不会太难)?
发布于 2013-05-20 17:44:10
在组合路径http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx上调用Path.GetFullPath
> Path.GetFullPath(Path.Combine(@"C:\blah\",@"..\bling"))
C:\bling
(我同意Path.Combine应该自己做这件事)
发布于 2016-06-01 04:13:41
对于windows通用应用程序,Path.GetFullPath()
不可用,您可以改用System.Uri
类:
Uri uri = new Uri(Path.Combine(@"C:\blah\",@"..\bling"));
Console.WriteLine(uri.LocalPath);
发布于 2013-07-17 18:31:22
这将为您提供所需的内容(path不需要存在即可运行)
DirectoryInfo di = new DirectoryInfo(@"C:\blah\..\bling");
string cleanPath = di.FullName;
https://stackoverflow.com/questions/670566
复制相似问题