2

Using ".." to jump up one level is the oldest feature of file system navigation - EVERY command line utility support it! (yes, thanks to OS shell) But when you use Path.Combine(), it works as a stupid string concatenator! Sample:

Path.Combine(@"c:\abc\def", @"..\XYZ")

Obviously we expect c:\abc\XYZ, while real result is c:\abc\def\..\XYZ. What a reason to embed Combine() into Path class if it knows nothing about elementary folder syntax? Same way it could be coded as String.Combine().

Is there any .NET solution, which can handle path concatenation properly?

New Dev
  • 48,427
  • 12
  • 87
  • 129
Vincent
  • 117
  • 5

1 Answers1

1

Fortunately there is simple solution - use standard function:

Path.GetFullPath(Path.Combine(@"C:\dir1\dir2", "..\dir3\file.txt")) => C:\dir1\dir3\file.txt
Vincent
  • 117
  • 5