PathCanonicalize相当于在C# [英] PathCanonicalize equivalent in C#

查看:248
本文介绍了PathCanonicalize相当于在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是等价于 PathCanonicalize 在C#?

使用:我需要带好猜两个文件路径是否引用相同的文件(没有磁盘访问)。我典型的做法已经把它扔通过像MakeAbsolute和PathCanonicalize几个过滤器,然后做一个区分大小写的比较。

Use: I need to take a good guess whether two file paths refer to the same file (without disk access). My typical approach has been throwing it through a few filters like MakeAbsolute and PathCanonicalize, and then do a case-insensitive comparison.

推荐答案

快速和肮脏的:

在过去,我已经创建了一个的从路径字符串的FileInfo 对象,然后使用FullName属性。这将删除所有..\的和.\年代

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.

当然,你可以互操作:

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

这篇关于PathCanonicalize相当于在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆