16,471
社区成员
发帖
与我相关
我的任务
分享
CFileFind finder;
std::vector<CString> fileList;
// 加入文件到fileList中
BOOL bHaveFiles = finder.FindFile("*.*");
while (bHaveFiles)
{
bHaveFiles = finder.FindNextFile();
fileList.push_back(finder.GetFileName());
}
// 写一个全局的谓词函数
// 升序排列
bool SortbyNumASC(const CString& x, const CString& y)
{
int nLeft, nRight;
nLeft = atoi(x.Left(x.ReverseFind('.')).GetBuffer(0));
nRight = atoi(y.Left(y.ReverseFind('.')).GetBuffer(0));
return nLeft<nRight;
}
// 降序排列
bool SortbyNumDESC(const CString& x, const CString& y)
{
int nLeft, nRight;
nLeft = atoi(x.Left(x.ReverseFind('.')).GetBuffer(0));
nRight = atoi(y.Left(y.ReverseFind('.')).GetBuffer(0));
return nLeft>nRight;
}
// 排序
/// 由大到小排
sort(fileList.begin(), fileList.end(), SortbyNumDESC);
/// 由小到大排
sort(fileList.begin(), fileList.end(), SortbyNumASC);