Finding something similar to Path.Combine for navigating folders

My colleague is looking for a method in System.IO that will do this:

var path1 = "c:\\temp\\foo\\bar"; var path2 = "..\\..\\foo2\\file.txt"; var path3 = Path.Combine2(path1, path2); // path3 = "c:\\temp\\foo2\\file.txt" 

Is there anything in System.IO for this type of combination, or will it have to write its own method? I could not find anything.

Thanks!

+4
source share
2 answers
 var path1 = "c:\\temp\\foo\\bar"; var path2 = "..\\..\\foo2\\file.txt"; var path3 = Path.GetFullPath(Path.Combine(path1, path2)).Normalize(); 
+9
source

That should do it;

 var path3 = Path.GetFullPath(Path.Combine(path1, path2)); 
+4
source

Source: https://habr.com/ru/post/1391919/


All Articles