How can one with minimal effort (using some already existing facility, if possible) convert paths like c:\aaa\bbb\..\ccc to c:\aaa\ccc?
How can one with minimal effort (using some already existing facility, if possible) convert paths like c:\aaa\bbb\..\ccc to c:\aaa\ccc?
Canonicalization is one of the main responsibilities of the Uri class in .NET.
var path = @"c:\aaa\bbb\..\ccc";
var canonicalPath = new Uri(path).LocalPath; // c:\aaa\ccc
FileInfo objects can also help here. (https://docs.microsoft.com/en-us/dotnet/api/system.io.fileinfo?view=net-5.0)
var x = Path.Combine(@"C:\temp", "..\\def/abc");
var y = new FileInfo(x).FullName; // "C:\\def\\abc"
FileInfo vs. DirectoryInfo can also help if you want to control the file vs. directory distinction.
But Path.GetFullPath is better if you just need the string.