关于在某个文件夹中遍历的问题 我如何遍历某个文件夹下的文件,按修改时间或创建时间先后顺序,将其文件名显示出来?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void BrowseDir(CString strDir) //此函数用于遍历文件夹下的文件,strDir是一个目录路径{ if(strDir == "") { MessageBox("error!"); return; } CFileFind ff; CString szDir = strDir,strPath; if(szDir.Right(1) != "\\") //保证目录是以\结尾的 szDir += "\\"; szDir += "*.*"; BOOL res = ff.FindFile(szDir); while( res ) { res = ff.FindNextFile(); strPath = ff.GetFilePath(); if(ff.IsDirectory() && !ff.IsDots()) BrowseDir(strPath); //如果目标是个文件夹,则利用嵌套来遍历 else if(!ff.IsDirectory() && !ff.IsDots()) DoSth(strPath); //如果目标是个文件,则对它进行处理 } ff.Close();} void ListFolder(CString sPath){ CFileFind ff; BOOL bFound = ff.FindFile(sPath + "\\*.*"); while(bFound){ bFound = ff.FindNextFile(); CString sFilePath = ff.GetFilePath(); if(ff.IsDirectory()){ if(!ff.IsDots()) ListFolder(sFilePath); } else ListFile(sFilePath);//这里记录的就是所有的文件 } ff.Close(); } step 1: 得到目录下所有文件存入m_strArrFilename.//xxx.hCStringArray m_strArrFilename;//xxx.cppvoid CTest6Dlg::OnButton1() { FindMyFile("D:\\1\\"); CString str="";}void CTest6Dlg::FindMyFile(CString path){ BOOL bFind, bFindSuffix; CFileFind tempFind, tempFind1; _chdir(path); bFind = tempFind.FindFile("*.*"); while(bFind) { bFind = tempFind.FindNextFile(); if(tempFind.IsDirectory()) { if (!tempFind.IsDots() ) { CString temppath; temppath = tempFind.GetFilePath(); FindMyFile(temppath); } } } _chdir(path); bFindSuffix = tempFind1.FindFile("*.*"); while(bFindSuffix) { bFindSuffix = tempFind1.FindNextFile(); CString filepath, filename; if( !tempFind1.IsDirectory() && !tempFind1.IsDots()) { filepath = tempFind1.GetFilePath(); m_strArrFilename.Add(filepath); } } tempFind.Close(); tempFind1.Close();}-----------------------------------------------step 2:得到文件的一些属性,并比较时间WIN32_FIND_DATA ffd;HANDLE hFind = FindFirstFile(m_strArrFilename[0], &ffd); FILETIME ftCreationTime = ffd.ftCreationTime;FILETIME ftLastWriteTime = ffd.ftLastWriteTime;然后比较所有文件的时间,进行排序 如何用postmessage发送组合键shift+f5(即模拟键盘上同时按下shift+f5) CComboBox 类中选择了列表中的一个值后会触发哪个时间? SPinEdit控件如何显示浮点数? CButton中的SetCursor()怎么不起作用? 怎么与QQ服务器通信? sql语句,选择问题,各位帮忙,在线等待(急) Windows2000端口問題! 请教动态库的问题! 怎么用CSerialPort类创建大于大于10的串口号 typedef struct{ } 怎么用呀? 自己没办法解决了,高手帮下忙,有重金酬劳 在vc中怎样实现掩码输入
{
if(strDir == "")
{
MessageBox("error!");
return;
}
CFileFind ff;
CString szDir = strDir,strPath;
if(szDir.Right(1) != "\\") //保证目录是以\结尾的
szDir += "\\";
szDir += "*.*";
BOOL res = ff.FindFile(szDir);
while( res )
{
res = ff.FindNextFile();
strPath = ff.GetFilePath();
if(ff.IsDirectory() && !ff.IsDots())
BrowseDir(strPath); //如果目标是个文件夹,则利用嵌套来遍历
else if(!ff.IsDirectory() && !ff.IsDots())
DoSth(strPath); //如果目标是个文件,则对它进行处理
}
ff.Close();
}
CFileFind ff;
BOOL bFound = ff.FindFile(sPath + "\\*.*");
while(bFound){ bFound = ff.FindNextFile();
CString sFilePath = ff.GetFilePath();
if(ff.IsDirectory()){
if(!ff.IsDots())
ListFolder(sFilePath);
} else ListFile(sFilePath);//这里记录的就是所有的文件
}
ff.Close();
}
得到目录下所有文件存入m_strArrFilename.//xxx.h
CStringArray m_strArrFilename;//xxx.cpp
void CTest6Dlg::OnButton1()
{
FindMyFile("D:\\1\\");
CString str="";
}
void CTest6Dlg::FindMyFile(CString path)
{
BOOL bFind, bFindSuffix;
CFileFind tempFind, tempFind1;
_chdir(path);
bFind = tempFind.FindFile("*.*");
while(bFind)
{
bFind = tempFind.FindNextFile();
if(tempFind.IsDirectory())
{
if (!tempFind.IsDots() )
{
CString temppath;
temppath = tempFind.GetFilePath();
FindMyFile(temppath);
}
}
}
_chdir(path);
bFindSuffix = tempFind1.FindFile("*.*");
while(bFindSuffix)
{
bFindSuffix = tempFind1.FindNextFile();
CString filepath, filename;
if( !tempFind1.IsDirectory() && !tempFind1.IsDots())
{
filepath = tempFind1.GetFilePath();
m_strArrFilename.Add(filepath);
}
}
tempFind.Close();
tempFind1.Close();
}
-----------------------------------------------
step 2:
得到文件的一些属性,并比较时间WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(m_strArrFilename[0], &ffd);
FILETIME ftCreationTime = ffd.ftCreationTime;
FILETIME ftLastWriteTime = ffd.ftLastWriteTime;然后比较所有文件的时间,进行排序