title: MFC CFindFile::FindNextFile usage
body: <p>The documentation for CFindFile states that</p>
  
  <blockquote>
    <p>Nonzero if there are more files; zero
    if the file found is the last one in
    the directory or if an error occurred.
    To get extended error information,
    call the Win32 function GetLastError.
    If the file found is the last file in
    the directory, or if no matching files
    can be found, the GetLastError
    function returns ERROR_NO_MORE_FILES.</p>
  </blockquote>
  
  <p>So how do I know if I have 1 file or 0 files if a call to FindNextFile returns the same value?</p>
  
  <p>It seems that a call to FindFile::GetFilePath() fails (which inadvertently causes my application to crash) if zero files are found. </p>
  
  <pre><code>pLog-&gt;Log(_T("Finding files in [%s]"), 1, szFilePath);
  
      if (!oFindFile.FindFile(szFilePath, 0))
  {
      pLog-&gt;Log(_T("Failed to find file in directory: [%s]"),1,szDirectory);
      return false;
  }
  
  bool moreFiles = true;
  while(moreFiles)
  {
      moreFiles = oFindFile.FindNextFile();
      if (oFindFile.IsDots())
      {
          continue;
      }
  
      CString szFileName = oFindFile.GetFilePath();
      pLog-&gt;Log(_T("Found file [%s]"), 1, szFileName);
      pVector-&gt;push_back(szFileName);
  }
  return true;
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>CString szFilePath = _T("C:\documents and settings\username\desktop\*.lnk");
  CString szDirectory = T("C:\documents and settings\username\desktop");
  </code></pre>