A file that is a directory is ed with FILE_ATTRIBUTE_DIRECTORY a file attribute identified in the WIN32_FIND_DATA structure.You must call FindNextFile at least once before calling IsDirectory.See the member function MatchesMask for a complete list of file attributes.
以上是在msdn上找到的,你仔细看看就明白了

解决方案 »

  1.   

    msdn上还有这么个例子:
    Example
    This small program recurses every directory on the C:\ drive and prints the name of the directory.#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();
    }void main()
    {
       if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0)
          cout << "panic!" << endl;
       else
          Recurse(_T("C:"));
    }
      

  2.   

    msdn上还有这么个例子:
    Example
    This small program recurses every directory on the C:\ drive and prints the name of the directory.#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();
    }void main()
    {
       if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0)
          cout << "panic!" << endl;
       else
          Recurse(_T("C:"));
    }
      

  3.   

    CFileFind finder;
    BOOL bFind;
    bFind=finder.FindFile(szFile);
    while(bFInd)
    {
                                bFind=finder.FindNextFile();
    //AfxMessageBox(szFile); //找到了szFile
    if(finder.IsDirectory())    //出错                            FindAllFilesInDirectory(szFile , m_lsFiles);//自己的方法
    else
    m_lsFiles.push_back(szFile);
    }