Declare Function FindClose Lib "kernel32.dll" (ByVal hFindFile As Long) As Long
Platforms: Win 32s, Win 95/98, Win NT
FindClose terminates a file-search operation initiated by FindFirstFile. This function closes the file search handle.
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: FindFirstFile, FindNextFile
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/findclose.html