Returns the next filename defined by the search handle.
FileFindNextFile ( search [, flag = 0])
search | The search handle, as returned by FileFindFirstFile(). |
flag | [optional] this flag determines whether to return detailed file attribute information in @extended. 0 = (default) use @extended to return 1 or 0 if search item is a directory. 1 = Return a string in @extended in the same format as FileGetAttrib(). |
Success: | a filename according to a previous call to FileFindFirstFile(), @extended set as per the flag option. |
Failure: | sets the @error flag to 1 if no more files/directories match the search. |
A previous call to FileFindFirstFile() is necessary to setup the search and get a search handle. Every subsequent call to FileFindNextFile() will return the next file found according to the search handle supplied to FileFindFirstFile(). When @error = 1, no more files found matching the original search handle.
When you have finished searching with the FileFind... functions you must call FileClose() to release the search handle.
Due to the underlying Windows API used (FindFirstFile), this function actually searches both the long and short filenames when looking for matches. If you get unexepected results
then verfiy that it's not the short filename that is being matched.
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Assign a Local variable the search handle of all files in the current directory.
Local $hSearch = FileFindFirstFile("*.*")
; Check if the search was successful, if not display a message and return False.
If $hSearch = -1 Then
MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.")
Return False
EndIf
; Assign a Local variable the empty string which will contain the files names found.
Local $sFileName = "", $iResult = 0
While 1
$sFileName = FileFindNextFile($hSearch)
; If there is no more file matching the search.
If @error Then ExitLoop
; Display the file name.
$iResult = MsgBox(($MB_OKCANCEL + $MB_SYSTEMMODAL), "", "File: " & $sFileName)
If $iResult <> $IDOK Then ExitLoop ; If the user clicks on the cancel/close button.
WEnd
; Close the search handle.
FileClose($hSearch)
EndFunc ;==>Example