How can one get an absolute or normalized file path in .NET?

后端 未结 3 1019
借酒劲吻你
借酒劲吻你 2020-11-29 09:54

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

3条回答
  •  没有蜡笔的小新
    2020-11-29 10:38

    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
    

提交回复
热议问题