By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

AutoIt FileFindNextFile Function

Reference on the FileFindNextFile Function of AutoIt. This function is used after FileFindFirstFile to find more files.

Edited: 2015-01-15 22:10

The AutoIt FileFindNextFile function finds the nest match in a file or directory search. This function is used after the FileFindFirstFile function.

Returns a filename on success, and sets @error to 0 if no files or directories matched the search. @extended will be set to 1 if the match is a directory.

FileFindNextFile Example

The below example script will find the next file in a search, until it runs out of matches.

; Return all files in the current directory.
Local $search = FileFindFirstFile("*.*")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    Local $file = FileFindNextFile($search)
    If @error Then ExitLoop

    MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)

@extended can be checked to tell directories apart from files, this can be done by modifying the loop to include an additional if else check.

While 1
    Local $file = FileFindNextFile($search)
    If @error Then ExitLoop
    
    ; Only return Files, ignore directories
    If NOT @extended Then
      MsgBox(4096, "File:", $file)
    EndIf

WEnd