结合绝对路径和相对路径 [英] Combine an absolute path with a relative path

查看:121
本文介绍了结合绝对路径和相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经定义了一条绝对路径

Let's say I have defined an absolute path

string abs = "X:/A/B/Q";

和相对路径

string rel = "../B/W";

我如何结合这两个,以便产生以下输出?

How do I combine these two so that it results in following output?

"X:/A/B/W"

我已经尝试过Path.Combine(),但是没有成功.

I already tried Path.Combine(), but not successfully.

推荐答案

尝试一下:

string abs = "X:/A/B/Q";
string rel = "../../B/W";
var path = Path.GetFullPath(Path.Combine(abs,rel));

它将给您完整的绝对路径 http://msdn.microsoft.com/en-us /library/system.io.path.getfullpath.aspx

It will give you full absolute path http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx

这篇关于结合绝对路径和相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆