Path.Combine和点符号符号、Path、Combine

由网友(℡雄起ゞ)分享简介:我在找一个类似于 Path.Combine 的方法,这将有助于我正确地结合绝对和相对路径。例如,我想I'm looking for something akin to Path.Combine method that will help me correctly combine absolute and relati...

我在找一个类似于 Path.Combine 的方法,这将有助于我正确地结合绝对和相对路径。例如,我想

I'm looking for something akin to Path.Combine method that will help me correctly combine absolute and relative paths. For example, I want

Path.Combine(@"c:alphabeta", @"..gamma");

C:阿尔法伽玛而不是 C:阿尔法 .. 伽玛 Path.Combine 一样。有没有实现这一点有没有简单的方法?不用说,我也想时期路径或多个 .. 路径(例如, .. .. )才能正常工作。

to yield c:alphagamma instead of c:alpha..gamma as Path.Combine does. Is there any easy way of accomplishing this? Needless to say, I also want to period . path or multiple .. paths (e.g., ....) to work correctly.

推荐答案

使用Path.GetFullPath

string path = Path.Combine(@"c:alphabeta", @"..gamma");
Console.WriteLine(Path.GetFullPath(path));

或DirectoryInfo类:

string path = Path.Combine(@"c:alphabeta", @"..gamma");
DirectoryInfo info = new DirectoryInfo(path);
Console.WriteLine(info.FullName);

双方将输出:

Both will output:

c:alphagamma
阅读全文

相关推荐

最新文章