【发布时间】:2014-01-27 18:44:55
【问题描述】:
我已经成功使用了C#中所谓的“Windows排序”,如下图所示。
public class NativeMethods
{
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, EntryPoint = "StrCmpLogicalW")]
public static extern int StrCmpLogical(string x, string y);
}
private class NaturalSortComparer : IComparer
{
public int Compare(object a, object b)
{
return NativeMethods.StrCmpLogical((string)a, (string)b);
}
}
来自 Unix 方面,我对 Microsoft 风格和 C++ 变体知之甚少,所以请耐心等待。
如何使用上述方法在 C++ 中对某些文件进行排序?以防万一:我没有在这个特定项目中使用 MFC。
我的文件在 C++ std::list 中,我需要按如下(或类似)对它们进行排序:
myFiles.sort();
【问题讨论】:
-
您为什么要为此进行 PInvoke?
Directory.EnumerateFiles应该为你做这件事。 -
只要写一个基于
StrCmpLogical的比较谓词,传递给sort。 -
“你为什么要为此做 PInvoke?”我需要以
10.开头的文件名放在9.之后你建议的方法可以吗? -
我想如果您搜索“自然排序”一词,您会找到一些答案。例如,see this question。