#include <Array.au3>
;Используется буфер обмена===========================================
$a = TimerInit()
Local $AllFiles = _FileDirList_('C:\Program Files (x86)','*',1); получаем строку для консоли - DIR "C:\Program Files (x86)\*" /B /S /A-D
Local $CorrectString = StringTrimRight($AllFiles,1)
$Result = StringSplit($CorrectString, @LF)
ConsoleWrite('_FileDirList+Буфер обмена: Время поиска - ' & TimerDiff($a) & '; Количество файлов - ' & $Result[0] & @LF)
_ArrayDisplay($Result,'Используем буфер обмена')
Func _FileDirList_($sPath, $sFileMask = "*", $iFlag = 0, $iSubDir = 1, $iSort = 0)
Local $sOutBin, $sOut, $aOut, $aMasks, $sRead, $hDir, $sAttrib, $sFiles
If Not StringInStr(FileGetAttrib($sPath), "D") Then
Return SetError(1, 0, 0)
EndIf
If $iSubDir = 1 Then
$sAttrib &= ' /S'
EndIf
If $iSort = 1 Then
$sAttrib &= ' /O:N'
EndIf
Switch $iFlag
Case 1
$sAttrib &= ' /A-D'
Case 2
$sAttrib &= ' /AD'
Case Else
$sAttrib &= ' /A'
EndSwitch
$sOut = StringToBinary('0' & @CRLF, 2)
$sPath = StringRegExpReplace($sPath, '\\+$', '')
$sFileMask = StringRegExpReplace($sFileMask, '^;+|;+$', '')
$sFileMask = StringRegExpReplace($sFileMask, ';{2,}', ';')
$aMasks = StringSplit($sFileMask, ';')
For $i = 1 To $aMasks[0]
If StringStripWS($aMasks[$i], 8) = "" Then
ContinueLoop
EndIf
$sFiles &= '"' & $sPath & '\' & $aMasks[$i] & '"'
If $i < $aMasks[0] Then
$sFiles &= ';'
EndIf
Next
$hDir = RunWait(@ComSpec & ' /U /C DIR ' & $sFiles & ' /B' & $sAttrib & ' | CLIP', @SystemDir, @SW_HIDE, 6)
Return ClipGet()
EndFunc
;==================================================================================================================
;Оригинальный вариант функции======================================================================================
$a = TimerInit()
Local $AllFiles = _FileDirList('C:\Program Files (x86)','*',1); получаем строку для консоли - DIR "C:\Program Files (x86)\*" /B /S /A-D
ConsoleWrite('_FileDirList: Время поиска - ' & TimerDiff($a) & '; Количество файлов - ' & $AllFiles[0] & @LF)
_ArrayDisplay($AllFiles,'Чтение из консоли')
Func _FileDirList($sPath, $sFileMask = "*", $iFlag = 0, $iSubDir = 1, $iSort = 0)
Local $sOutBin, $sOut, $aOut, $aMasks, $sRead, $hDir, $sAttrib, $sFiles
If Not StringInStr(FileGetAttrib($sPath), "D") Then
Return SetError(1, 0, 0)
EndIf
If $iSubDir = 1 Then
$sAttrib &= ' /S'
EndIf
If $iSort = 1 Then
$sAttrib &= ' /O:N'
EndIf
Switch $iFlag
Case 1
$sAttrib &= ' /A-D'
Case 2
$sAttrib &= ' /AD'
Case Else
$sAttrib &= ' /A'
EndSwitch
$sOut = StringToBinary('0' & @CRLF, 2)
$sPath = StringRegExpReplace($sPath, '\\+$', '')
$sFileMask = StringRegExpReplace($sFileMask, '^;+|;+$', '')
$sFileMask = StringRegExpReplace($sFileMask, ';{2,}', ';')
$aMasks = StringSplit($sFileMask, ';')
For $i = 1 To $aMasks[0]
If StringStripWS($aMasks[$i], 8) = "" Then
ContinueLoop
EndIf
$sFiles &= '"' & $sPath & '\' & $aMasks[$i] & '"'
If $i < $aMasks[0] Then
$sFiles &= ';'
EndIf
Next
$hDir = Run(@ComSpec & ' /U /C DIR ' & $sFiles & ' /B' & $sAttrib, @SystemDir, @SW_HIDE, 6)
While ProcessExists($hDir)
$sRead = StdoutRead($hDir, False, True)
If @error Then
ExitLoop
EndIf
If $sRead <> "" Then
$sOut &= $sRead
EndIf
WEnd
$aOut = StringRegExp(BinaryToString($sOut, 2), '[^\r\n]+', 3)
If @error Or UBound($aOut) < 2 Then
Return SetError(2, 0, 0)
EndIf
$aOut[0] = UBound($aOut) - 1
Return $aOut
EndFunc