请问如何搜索文件夹下的文件包括子文件夹 请问如何搜索文件夹下的所有文件包括子文件夹?请问采用什么方法呢?在MFC中有现成的函数吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CStringArray m_strArrFilename;void CTest6Dlg::OnButton1(){ FindMyFile("d:\\temp\\"); CString strtemp; for(int i=0; i<m_strArrFilename.GetSize(); i++) { strtemp += m_strArrFilename[i] + "\r\n"; } AfxMessageBox(strtemp);}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();} void Recurse(LPCTSTR pstr){ CFileFind finder; // build a string with wildcards CString strWildcard(pstr); strWildcard += _T("\\*.*"); // start working for files BOOL bWorking = finder.FindFile(strWildcard); while (bWorking) { bWorking = finder.FindNextFile(); // skip . and .. files; otherwise, we'd // recur infinitely! if (finder.IsDots()) continue; // if it's a directory, recursively search it if (finder.IsDirectory()) { CString str = finder.GetFilePath(); cout << (LPCTSTR) str << endl; Recurse(str); } } finder.Close();} webbrowser控件 跟CHtmlView 什么关系? CTreeCtrl 如何动态把节点文字加上 下划线? 有关CTreeCtrl的问题 显示一个对话框到屏幕的右下角,怎么做? 安装了vs6,突然不能访问某个电脑了 对最大化按钮的处理问题 问一个比较基础的问题,关于MTS 数码相机开发包 FFMPEG库解码1080P帧率60帧延时 opencv 2.4.8谁有好的学习建议吗? 或者资料 如何禁止视频? 如何在VC代码中对任务栏菜单进行操作?
void CTest6Dlg::OnButton1()
{
FindMyFile("d:\\temp\\"); CString strtemp; for(int i=0; i<m_strArrFilename.GetSize(); i++) { strtemp += m_strArrFilename[i] + "\r\n"; } AfxMessageBox(strtemp);
}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();}
{
CFileFind finder; // build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("\\*.*"); // start working for files
BOOL bWorking = finder.FindFile(strWildcard); while (bWorking)
{
bWorking = finder.FindNextFile(); // skip . and .. files; otherwise, we'd
// recur infinitely! if (finder.IsDots())
continue; // if it's a directory, recursively search it if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
cout << (LPCTSTR) str << endl;
Recurse(str);
}
} finder.Close();
}