C# 使用Shlwapi.dll 进行文件排序

妖精的绣舞 提交于 2019-11-27 02:57:31

C# 使用Shlwapi.dll 进行文件排序

代码

public class FileComparer : IComparer<string>
{
    [System.Runtime.InteropServices.DllImport("Shlwapi.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
    public static extern int StrCmpLogicalW(string psz1, string psz2);
    public int Compare(string psz1, string psz2)
    {
        return StrCmpLogicalW(psz1, psz2);
    }
}

使用

List list = FileList.OrderBy(x => x.Replace(“END”, ""), new FileComparer()).ToList();
这样的排序和资源管理器中的排序规则一致

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!