void find(char *lpPath)
{
char szFind[MAX_PATH];
char szFile[MAX_PATH];
CString info;
WIN32_FIND_DATA FindFileData;
strcpy(szFind,lpPath);
strcat(szFind,"\\*.*");
HANDLE hFind="::FindFirstFile"(szFind,&FindFileData);
if(INVALID_HANDLE_VALUE == hFind) return;
while(TRUE)
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(FindFileData.cFileName[0]!='.')
{
strcpy(szFile,lpPath);
strcat(szFile,"\\");
strcat(szFile,FindFileData.cFileName);
find(szFile);
}
}
else
{ //deal with FindFileData.cFileName
}
if(!FindNextFile(hFind,&FindFileData)) break;
}
FindClose(hFind);
}
=====================================================================
#include <afxwin.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;
CString sFileName = finder.GetFileName();
cout << (LPCTSTR)sFileName << endl;//输出查找文件夹下的所有文件名
}
finder.Close();
}
int main()
{
if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0))//初始化MFC
cout << "panic!" << endl;
else
Recurse(_T("C:"));
return 0;
}
以上来自
文章评论(0条评论)
登录后参与讨论