搜索文件时如何区分搜索到的是目录还是文件 我要搜索文件a.txt 可我不知道a.txt在哪个目录 搜索时当搜索到文件时比较文件名后进入搜索下一文件或目录 搜索到目录时进入目录搜索 请问我如何区分当前我搜索到的是目录还是文件呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 摘自MSDN#include <afx.h>#include <iostream>using namespace std;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();} 如果是用MFC的话,楼上的就可以了如果要使用API来做的文件搜索DWORD GetFileAttributes( LPCTSTR lpFileName // name of file or directory);if(GetFileAttributes(_T("文件名")) & FILE_ATTRIBUTE_DIRECTORY){ // 目录}else{ // 文件} 定制浏览器的问题 怎样使得编辑框只能顺序输入字符 请问odbc问题 谁有Programming Windows With MFC 2nd 中文版电子书 如何在MFC中截留 F1--F12 键的按键消息 哪里有VC++自画的 标尺 控件?谢谢 请问一个程序PostMessage后怎么让它进入等待状态,不去处理该消息?? 怎样给一个ClistView SendMessage()一触发NM_DBLCLK消息事件? 侯捷这人写的书还真它妈得不错,深入浅出 MFC/2E 真是好 那儿有C++ STL的习题答案下载? 多线程 对扫描出来的图片 进行文字识别
#include <afx.h>
#include <iostream>using namespace std;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();
}
DWORD GetFileAttributes(
LPCTSTR lpFileName // name of file or directory
);if(GetFileAttributes(_T("文件名")) & FILE_ATTRIBUTE_DIRECTORY)
{
// 目录
}
else
{
// 文件
}