#include <Array.au3>
$iStart = TimerInit()
$aReturn = _FileSearch(@ScriptDir & "\1\", '*.au3|*.txt', 1)
$sTime = StringFormat('%.2f sec', TimerDiff($iStart) / 1000)
_ArrayDisplay($aReturn, $sTime)
Func _FileSearch($s_Path_Search, $s_File_Mask = '*', $i_Flag = 0, $i_SubDir = 1)
Local $s_Out, $a_Out, $s_Read, $h_Dir, $s_Attrib, $s_Subdir, $s_Parameter, $a_Masks
If StringRight($s_Path_Search, 1) == '\' Then
$s_Path_Search = StringTrimRight($s_Path_Search, 1)
EndIf
$a_Masks = StringSplit($s_File_Mask, '|')
For $i = 1 To $a_Masks[0]
$s_Parameter &= '"' & $s_Path_Search & '\' & $a_Masks[$i] & '";'
Next
$s_Parameter = StringTrimRight($s_Parameter, 1)
If $i_SubDir Then
$s_Subdir = ' /S /B'
Else
$s_Subdir = ' /B'
EndIf
Switch $i_Flag
Case 1
$s_Attrib = ' /A-D'
Case 2
$s_Attrib = ' /AD'
Case Else
$s_Attrib = ' /A'
EndSwitch
$s_Parameter &= $s_Subdir & $s_Attrib
$s_Out = StringToBinary('0' & @CRLF, 2)
$h_Dir = Run(@ComSpec & ' /U /C DIR ' & $s_Parameter, @SystemDir, @SW_HIDE, 6)
If Not $h_Dir Then Return SetError(1)
While 1
$s_Read = StdoutRead($h_Dir, False, True)
If @error Then
ExitLoop
EndIf
If $s_Read Then
$s_Out &= $s_Read
EndIf
Sleep(10)
WEnd
$a_Out = StringRegExp(BinaryToString($s_Out, 2), '[^\r\n]+', 3)
If @error Then Return SetError(1)
$a_Out[0] = UBound($a_Out) - 1
Local $a_OutFilter[1] = [0]
For $i = 1 To $a_Out[0]
$a_Del = StringSplit($a_Out[$i], ".")
If StringRegExp($s_File_Mask, $a_Del[$a_Del[0]]) = 1 Then
$a_OutFilter[0] += 1
ReDim $a_OutFilter[$a_OutFilter[0]+ 1]
$a_OutFilter[$a_OutFilter[0]] = $a_Out[$i]
EndIf
;ConsoleWrite($a_Del[$i] & @CRLF)
Next
Return $a_OutFilter
EndFunc