another approach
; https://www.autoitscript.com/forum/topic/211902-code-to-obtain-only-the-first-file-of-the-a-lot-of-folders/
#include <File.au3>
_FindAllDir(@MyDocumentsDir)
;----------------------------------------------------------------------------------------
Func _FindAllDir($dir)
If StringRight($dir, 1) <> "\" Then $dir &= "\"
$ArraySrtfiles = _FileListToArrayRec($dir, "*", $FLTAR_FOLDERS, $FLTAR_RECUR)
If Not IsArray($ArraySrtfiles) Then
ConsoleWrite($dir & " = Invalid input path" & @CRLF)
Return
Else
Local $sResult
For $x = 1 To $ArraySrtfiles[0]
;ConsoleWrite($dir & $ArraySrtfiles[$x] & @CRLF)
$sResult = _FindAllFile($dir & $ArraySrtfiles[$x], "*.txt")
If Not @error Then ConsoleWrite($sResult & @CRLF)
Next
EndIf
EndFunc ;==>_FindAllDir
;----------------------------------------------------------------------------------------
Func _FindAllFile($dir, $FileMask)
$ArraySrtfiles = _FileListToArrayRec($dir, $FileMask, $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT)
If Not IsArray($ArraySrtfiles) Then
Return SetError(1, 0, "")
Else
Local $sResult
For $x = 1 To $ArraySrtfiles[0]
$sResult = $dir & $ArraySrtfiles[$x]
Return $sResult
Next
EndIf
EndFunc ;==>_FindAllFile
;----------------------------------------------------------------------------------------