劳烦大家帮我看看下面这两个函数,要实现的功能是搜索硬盘上所有.doc文件,现在的问题是不能全部搜索到。void SearchMyCompter::GetLocalDrives()
{
TCHAR buf[100];
DWORD len = GetLogicalDriveStrings(sizeof(buf)/sizeof(TCHAR), buf); CString strDisks;
for (TCHAR* sDrivePath = buf; *sDrivePath; sDrivePath += _tcslen(sDrivePath)+1)
{
SearchFile(sDrivePath);
}
}void SearchMyCompter::SearchFile(TCHAR* sDrivePath)
{
CFileFind tempFind;
WCHAR tempFileFind[MAX_PATH];
wsprintf(tempFileFind, L"%s\\*", sDrivePath); BOOL isFinded = (BOOL)tempFind.FindFile(tempFileFind);
  while(isFinded)
{
if(!tempFind.IsDots())
{
CString foundFileName;
CString tempFile;
LPTSTR lpFileExtension; foundFileName = tempFind.GetFileName();
tempFile.Format(L"%s\\%s", sDrivePath, foundFileName);
lpFileExtension = PathFindExtension(foundFileName);
if(tempFind.IsDirectory()) //如果是目录,则递归地调用UploadFile
{
TCHAR tempDir[MAX_PATH];
wsprintf(tempDir, L"%s", tempFile);
SearchFile(tempDir);
}
else if(wcscmp(lpFileExtension, L".doc") == 0)
{
AfxMessageBox(tempFile);
}
}
isFinded = (BOOL)tempFind.FindNextFile();//递归搜索其他文件
}
tempFind.Close();
}

解决方案 »

  1.   

    CFileFind find;
    CString filename;
    handle hand = find.findfile("*.doc")
    while(hand)
    {   filename = find.getfilename();
       hand = find.findnext();}
      

  2.   

    isFinded = (BOOL)tempFind.FindNextFile();//递归搜索其他文件
    这一句应该写在if外面。因为即使是文件夹也要findnextfile。
    可能是这样的。你自己调试一下
      

  3.   

    wsprintf(tempFileFind, L"%s\\*.*", sDrivePath);
      

  4.   

    谢谢,我一直认为要先处理tempFind.FindFile()文件,再处理其他文件,所以就把isFinded = (BOOL)tempFind.FindNextFile();放在后面了, 其实不然。