Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Platforms: Win 32s, Win 95/98, Win NT
FindNextFile continues a file search began by FindFirstFile. It finds and provides identifying information about the next file that matches the search string. This information is put into the variable passed as lpFindFileData. The function returns 1 if another matching file was found, or 0 if no more matching files exist (or if an error occured).
Example:
' Search for all files that match "C:\MyProgram\user*.*". Display
' the filename of each file that matches the string.
Dim hsearch As Long ' handle to the file search
Dim findinfo As WIN32_FIND_DATA ' receives info about matching files
Dim success As Long ' will be 1 if successive searches are successful, 0 if not
Dim buffer As Long ' string buffer to use to process the filename(s)
Dim retval As Long ' generic return value
' Begin a file search:
hsearch = FindFirstFile("C:\MyProgram\user*.*", findinfo)
If hsearch = -1 Then ' no files match the search string
Debug.Print "(no files matched search parameter)"
End ' abort program
End If
' Display name of each file that matches the search. Note that the name is displayed, the
' next file (if any) is found, and then the loop restarts. This way the first file
' (found above) will also be displayed.
Do ' begin loop
' Extract the filename from the fixed-length string:
buffer = Left(findinfo.cFileName, InStr(findinfo.cFileName, vbNullChar) - 1)
Debug.Print buffer ' display this filename
' Get the next matching file and loop if it exists:
success = FindNextFile(hsearch, findinfo)
Loop Until success = 0 ' keep looping until no more matching files are found
' Close the file search handle
retval = FindClose(hsearch)
See Also: FindClose, FindFirstFile
Category: Files
Go back to the alphabetical Function listing.
Go back to the Reference section index.
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/f/findnextfile.html