tags:

views:

222

answers:

2

Dear ladies and sirs.

How can one with minimal effort (using some already existing facility, if possible) to convert paths like c:\aaa\bbb\..\ccc to c:\aaa\ccc ?

+6  A: 

Path.GetFullPath perhaps?

leppie
I do not believe this is guaranteed to return a canonical name. It only guarantees the name returned can be used to reference the file absolutely vs. relatively
JaredPar
Stupid me. Thanks.
mark
Path.GetFullPath(@"c:\aaa\bbb\..\ccc") = c:\aaa\ccc - good enough for me.
mark
Correct, but it doesn't check if the path is valid.
Henk Holterman
@Henk: Path utils should not actually check for a valid file, or even touch the file system (but there are a few cases it does).
leppie
+4  A: 

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
bdukes