#include <Array.au3>
$aFiles = _FileSearch(@DesktopDir, "*.txt")
_ArrayDisplay($aFiles)
Func _FileSearch($sPath, $sMask="*")
If Not StringInStr(FileGetAttrib($sPath & "\"), "D") Then Return SetError(1, 0, 0)
Local $hSearch, $sFindNext, $sFilePath, $iPathIsFolder, $i = 0, $sRet = ""
Local $sRegExpFilter = StringReplace(StringReplace(StringReplace($sMask, ".", "\."), "*", ".*"), "?", ".")
Local $iMax_Ret_Paths = 10000
Local $aPathesArr[$iMax_Ret_Paths+1] = [1, $sPath]
While $i < $aPathesArr[0]
$i += 1
$hSearch = FileFindFirstFile($aPathesArr[$i] & "\*")
If $hSearch = -1 Then ContinueLoop
While 1
$sFindNext = FileFindNextFile($hSearch)
If @error Then ExitLoop
$sFilePath = $aPathesArr[$i] & "\" & $sFindNext
$iPathIsFolder = StringInStr(FileGetAttrib($sFilePath & "\"), "D")
If $iPathIsFolder Then
If $aPathesArr[0] >= $iMax_Ret_Paths Then
$iMax_Ret_Paths *= 2
ReDim $aPathesArr[$iMax_Ret_Paths+1]
EndIf
$aPathesArr[0] += 1
$aPathesArr[$aPathesArr[0]] = $sFilePath
ElseIf StringRegExp($sFindNext, "(?i)\A" & $sRegExpFilter & "\z") Then
$sRet &= $sFilePath & @CRLF
EndIf
WEnd
FileClose($hSearch)
WEnd
$sRet = StringSplit(StringStripWS($sRet, 3), @CRLF, 1)
If @error Then Return SetError(1, 0, -1)
Return $sRet
EndFunc