0

I'm trying to join two relative paths to create another relative (NOT absolute) path using Path.Combine.

string path1=@"rootDir\DirA\DirAA";
string path2=@"..\..\DirB";
Console.WriteLine(Path.Combine(path1, path2));
//I get: rootDir\DirA\DirAA\..\..\DirB
Console.WriteLine(Path.GetFullPath(Path.Combine(path1, path2)));
//I get: C:User\rootDir\DirB

What I actually want is

//rootDir\DirB

Is there any way to accomplish that using Path?

Bighted19
  • 119
  • 7
  • can you split the path string at "\" and combine the parts you want ? – Naruto Oct 07 '18 at 16:43
  • Possible duplicate of [Path.Combine absolute with relative path strings](https://stackoverflow.com/questions/670566/path-combine-absolute-with-relative-path-strings) – Matthew Eskolin Oct 07 '18 at 16:49
  • @blueprogrammer No, I am looking for the relative path from the combination of two relative paths and not the absolute path. – Bighted19 Oct 07 '18 at 17:04

1 Answers1

0

Try this:

Path.GetFullPath(Path.Combine(path1, path2))
    .Substring(Directory.GetCurrentDirectory().Length + 1);
smolchanovsky
  • 1,775
  • 2
  • 15
  • 29