代码
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();
这样的排序和资源管理器中的排序规则一致