DOC: FindNextFile Returns 0 for Last File Found (166505)



The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), when used with:
    • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
    • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
    • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
    • Microsoft Visual C++, 32-bit Professional Edition 4.2
    • Microsoft Visual C++, 32-bit Professional Edition 5.0
    • Microsoft Visual C++, 32-bit Professional Edition 6.0
    • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q166505

SUMMARY

The documentation for CFileFind::FindNextFile, CFtpFileFind::FindNextFile, and CGopherFileFind::FindNextFile in the Class Library Reference with Visual C++ is incorrect. The documentation states:
   Return Value

   Nonzero if successful; otherwise 0. To get extended error information,
   call the Win32 function GetLastError.
				
The documentation should read:
   Return Value

   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.
				

MORE INFORMATION

The code below shows how to use CFileFind::FindNextFile to find every file in a directory.

Sample Code

   CFileFind finder;
   BOOL bWorking = finder.FindFile("*.*");
   while (bWorking)
   {
       bWorking = finder.FindNextFile();
       // Do processing here
   }
				

REFERENCES

See the CFileFind overview in the Visual C++ documentation.

Modification Type:MajorLast Reviewed:12/2/2003
Keywords:kbBug kbdocerr kbdocfix kbFileIO kbNoUpdate kbpending kbusage KB166505