MFC遍历文件FindNextFile(),怎样控制文件遍历的顺序? mfc遍历顺序 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 既然知道命名格式 为什么不用个 for循环for(int i = 1;i<100;i++){ ..... str.Format("%d.bmp",i); .......} system("dir /b /a-d /os c:\\*.* >d:\\allfiles.txt");//读文件d:\\allfiles.txt的内容即C:\\下所有文件的名字,按文件大小从小到大顺序system("dir /b /a-d /s /o-d c:\\*.* >d:\\allfilesinsub.txt");//读文件d:\\allfilesinsub.txt的内容即C:\\下所有文件的名字包含子目录,按文件时间从新到旧顺序system("dir /b /ad c:\\*.* >d:\\alldirs.txt");//读文件d:\\alldirs.txt的内容即C:\\下所有子目录的名字请记住,能用shell命令获取文件、文件夹信息或者操作文件、文件夹最好用shell命令获取或者操作,而不要用各种API获取或者操作,因为当遇到非法文件夹名或非法文件名或非法文件长度、非法文件日期、压缩文件、链接文件、稀疏文件……等各种意料之外的情况时,API会处理的不全面或陷入死循环,而shell命令不会。 按照上面人说的啊先乱序读入vector之类的容器然后自己写个排序函数就得到你的内容了或者看下#7的说明,反正我看不太懂 用set或map来存储,开发自定义的比较函数,这样存储进去,就是按照你的期望有序的了 //集合#include <vector>#define VEC_STRING std::vector<CString>VEC_STRING VecImageName;//图片文件夹的图片名称集合GetFloderVecImageName(szImageFloderPath, VecImageName);//获取图片名称集合sort(VecImageName.begin(), VecImageName.end(), CmpImageName);/************************************************************* 功能描述: 获取文件夹下的图片名称集合************************************************************/void CReadImageDataDlg::GetFloderVecImageName(CString szPath, VEC_STRING& VecImageName){ CFileFind ff; BOOL bFind = ff.FindFile(szPath + _T("\\*.*")); while(bFind) { bFind = ff.FindNextFile(); if (ff.IsDots() || ff.IsSystem() || ff.IsHidden() || ff.IsDirectory()) { continue; } else { CString szFilePath = ff.GetFilePath(); CString szExt = HandlePath::GetFileExt(szFilePath);//文件后缀 //判断文件后缀 if (_T("bmp") != szExt) { continue; } CString szFileName = ff.GetFileName(); //判断文件名称 //if (szFileName.Left(4) != _T("IMG_")) //{ // continue; //} //添加图片名称 VecImageName.push_back(szFileName); } }}//用来做图片名称比较函数bool CmpImageName(CString &string1, CString &string2){ CString szNum1 = string1.Mid(4, string1.GetLength() - 8); int nNum1 = _ttoi(szNum1); CString szNum2 = string2.Mid(4, string2.GetLength() - 8); int nNum2 = _ttoi(szNum2); if (nNum1 < nNum2) { return true; } else { return false; }} memcpy_s拷贝请教 散分 csdn 的朋友们 2010 好运 first-chance exception...:access violate, odbc连oracle执行sqlexecdirect时报错 对话框关闭的问题 请问VC中调用_outp函数需要包含什么头文件? =======100分求助一个问题======== 请问ACSII,UCS2,GBK编码之间如何转换?急! 有谁用过大恒公司得DH-CG400得图像采集卡? 高分征求建议! 如何显示次方 Unhandle exception 错误 关于GDI+对象的释放问题
for(int i = 1;i<100;i++)
{
.....
str.Format("%d.bmp",i);
.......
}
//读文件d:\\allfiles.txt的内容即C:\\下所有文件的名字,按文件大小从小到大顺序
system("dir /b /a-d /s /o-d c:\\*.* >d:\\allfilesinsub.txt");
//读文件d:\\allfilesinsub.txt的内容即C:\\下所有文件的名字包含子目录,按文件时间从新到旧顺序
system("dir /b /ad c:\\*.* >d:\\alldirs.txt");
//读文件d:\\alldirs.txt的内容即C:\\下所有子目录的名字
请记住,能用shell命令获取文件、文件夹信息或者操作文件、文件夹最好用shell命令获取或者操作,而不要用各种API获取或者操作,因为当遇到非法文件夹名或非法文件名或非法文件长度、非法文件日期、压缩文件、链接文件、稀疏文件……等各种意料之外的情况时,API会处理的不全面或陷入死循环,而shell命令不会。
按照上面人说的啊先乱序读入vector之类的容器
然后自己写个排序函数
就得到你的内容了或者看下#7的说明,反正我看不太懂
#include <vector>#define VEC_STRING std::vector<CString>VEC_STRING VecImageName;//图片文件夹的图片名称集合GetFloderVecImageName(szImageFloderPath, VecImageName);//获取图片名称集合sort(VecImageName.begin(), VecImageName.end(), CmpImageName);/***********************************************************
** 功能描述: 获取文件夹下的图片名称集合
************************************************************/
void CReadImageDataDlg::GetFloderVecImageName(CString szPath, VEC_STRING& VecImageName)
{
CFileFind ff; BOOL bFind = ff.FindFile(szPath + _T("\\*.*")); while(bFind)
{
bFind = ff.FindNextFile(); if (ff.IsDots()
|| ff.IsSystem()
|| ff.IsHidden()
|| ff.IsDirectory())
{
continue;
}
else
{
CString szFilePath = ff.GetFilePath(); CString szExt = HandlePath::GetFileExt(szFilePath);//文件后缀 //判断文件后缀
if (_T("bmp") != szExt)
{
continue;
} CString szFileName = ff.GetFileName(); //判断文件名称
//if (szFileName.Left(4) != _T("IMG_"))
//{
// continue;
//} //添加图片名称
VecImageName.push_back(szFileName);
}
}
}//用来做图片名称比较函数
bool CmpImageName(CString &string1, CString &string2)
{
CString szNum1 = string1.Mid(4, string1.GetLength() - 8);
int nNum1 = _ttoi(szNum1); CString szNum2 = string2.Mid(4, string2.GetLength() - 8);
int nNum2 = _ttoi(szNum2); if (nNum1 < nNum2)
{
return true;
}
else
{
return false;
}
}