PathCanonicalize equivalent in C#

前端 未结 3 1557
醉酒成梦
醉酒成梦 2021-01-12 00:07

What is the equivalent to PathCanonicalize in C#?

Use: I need to take a good guess whether two file paths refer to the same file (without disk access). My typical ap

3条回答
  •  逝去的感伤
    2021-01-12 00:54

    quick and dirty:

    In the past I have created a FileInfo object from the path string and then used the FullName property. This removes all of the ..\'s and the .\'s.

    Of course you could interop:

     [DllImport("shlwapi", EntryPoint="PathCanonicalize")]
        private static extern bool PathCanonicalize(
            StringBuilder lpszDst,
            string lpszSrc
        );
    

提交回复
热议问题