#include <Array.au3> ; для _ArrayDisplay ; i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i! ; все файлы папки WINDOWS в виде массива $timer = TimerInit() $FileList=_FileSearch(@WindowsDir, '*', True, 100) $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек' _ArrayDisplay($FileList, $timer&' - все файлы') ; i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i! ; только файлы exe и dll папки WINDOWS в виде списка $timer = TimerInit() $FileList=_FileSearch(@WindowsDir, 'exe;dll', True, 0, 1, 0) $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек' MsgBox(0, $timer&' - exe;dll', $FileList) ; i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i! ; все файлы, кроме exe и dll папки WINDOWS в виде списка с относительными путями $timer = TimerInit() $FileList=_FileSearch(@WindowsDir, 'exe;dll', False, 0, 0, 0) $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек' MsgBox(0, $timer&' - кроме exe;dll, относит. пути', $FileList) ; i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i! ; все файлы, кроме exe и dll папки WINDOWS в виде списка с именами файлов без расширения $timer = TimerInit() $FileList=_FileSearch(@WindowsDir, 'exe;dll', False, 0, 3, 0) $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек' MsgBox(0, $timer&' - кроме exe;dll, имя без расширения', $FileList) ; i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i! ; только файлы tmp и bak и gid папки WINDOWS в виде массива с относительными путями, массив без указания количества файлов $timer = TimerInit() $FileList=_FileSearch(@WindowsDir, 'tmp;bak;gid', True, 100, 0, 2) $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек' _ArrayDisplay($FileList, $timer&' - tmp;bak;gid, относит. пути, первый эл. файл') ; i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i! ; только файлы tmp и bak и gid папки WINDOWS в виде массива с именами файлов c расширения $timer = TimerInit() $FileList=_FileSearch(@WindowsDir, 'tmp;bak;gid', True, 100, 2) $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек' _ArrayDisplay($FileList, $timer&' - tmp;bak;gid, имена с расширением') ; i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i! ; Недопустимый символ в пути $FileList=_FileSearch('C:\WIN>DOWS', '*') If @error Then MsgBox(0, 'Ошибка', 'Код ошибки: '&@error) Exit EndIf ; i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i! ; ============================================================================================ ; Function Name ...: _FileSearch (__FileSearch, __FileSearchAll) ; AutoIt Version ....: 3.3.2.0+ , versions below this @extended should be replaced by of StringInStr(FileGetAttrib($Path&'\'&$file), "D") ; Description ........: Search files by mask in subdirectories. ; Syntax................: _FileSearch($Path[, $Mask = '*' [, $Include=True [, $Level=100 [, $Full=1 [, $Arr=1]]]]]) ; Parameters: ; $Path - search path ; $Mask - mask, the mask is allowed normal function FileFindFirstFile, or a list of extensions with the separator ";" ; $Include - (True / False) invert the mask, that is excluded from the search for these types of files ; $Level - (0-100) nesting level (0 - root directory) ; $Full - (0,1,2,3) ; |0 - relative ; |1 - full path ; |2 - file names with extension ; |3 - file names without extension ; $Arr - if the value other than zero, the result is an array (by default ), ; |0 - a list of paths separated by @CRLF ; |1 - result in an array where $array[0]=number of files ( by default) ; |2 - result in an array, where $array[0] contains the first file ; Return values ....: Success - Array ($array[0]=number of files) or a list of paths separated by @CRLF ; Failure - empty string, @error: ; |0 - no error ; |1 - Invalid path ; |2 - Invalid mask ; Author(s) ..........: AZJIO ; Remarks ..........: If an empty folder, it returns an empty string or array with one element $array[0]=0, @error=0 ; ============================================================================================ ; Имя функции ...: _FileSearch (__FileSearch, __FileSearchAll) ; Версия AutoIt ..: 3.3.2.0+ , в версиях ниже указанной нужно @extended заменить на StringInStr(FileGetAttrib($Path&'\'&$file), "D") ; Описание ........: Поиск файлов по маске в подкаталогах. ; Синтаксис.......: _FileSearch($Path[, $Mask = '*' [, $Include=True [, $Level=100 [, $Full=1 [, $Arr=1]]]]]) ; Параметры: ; $Path - путь поиска ; $Mask - маска, допустима обычная маска функции FileFindFirstFile, либо перечисление расширений через ";" ; $Include - (True / False) инвертировать маску, то есть исключить из поиска указанные типы файлов ; $Level - (0-100) уровень вложенности (0 - корневой каталог) ; $Full - (0,1,2,3) ; |0 - относительный ; |1 - полный путь ; |2 - имена файлов с расширением ; |3 - имена файлов без расширения ; $Arr - (0,1,2) определяет вывод результата, массив или список ; |0 - список с разделителем @CRLF ; |1 - результат в виде массива, где $array[0]=количество файлов (по умолчанию) ; |2 - результат в виде массива, в котором $array[0] содержит первый файл ; Возвращаемое значение: Успешно - Массив ($array[0]=количество файлов) или список с разделителем @CRLF ; Неудачно - пустая строка, @error: ; |0 - нет ошибок ; |1 - неверный путь ; |2 - неверная маска ; Автор ..........: AZJIO ; Примечания ..: Если пустая папка, то возвращается пустая строка или массив с одной ячейкой $array[0]=0, при этом @error=0 ; ============================================================================================ ; функция проверки и подготовки входных параметров и обработка результирующего списка Func _FileSearch($Path, $Mask = '*', $Include=True, $Level=100, $Full=1, $Arr=1) Local $FileList If Not StringRegExp($Path, '(?i)^[a-z]:[^/:*?"<>|]*$') Or StringInStr($Path, '\\') Then Return SetError(1, 0, '') If StringRight($Path, 1)='\' Then $Path=StringTrimRight($Path, 1) If $Mask = '' Then $Mask = '*' If StringInStr($Mask, '*') Or StringInStr($Mask, '?') Then If StringRegExp($Mask, '[\\/:"<>|]') Then Return SetError(2, 0, '') $FileList=StringTrimRight(__FileSearchAll($Path, $Mask, $Level), 2) Else If StringRegExp($Mask, '[\\/:*?"<>|]') Then Return SetError(2, 0, '') $Mask=';.'&StringReplace($Mask, ';', ';.')&';' $FileList=StringTrimRight(__FileSearch($Path, $Mask, $Include, $Level), 2) EndIf Switch $Full Case 0 $FileList=StringRegExpReplace($FileList, '(?m)^(?:.{'&StringLen($Path)+1&'})(.*)$', '\1') Case 2 $FileList=StringRegExpReplace($FileList, '(?m)^(?:.*\\)(.*)$', '\1') Case 3 $FileList=StringRegExpReplace($FileList, '(?m)^(?:.*\\)([^\\]*?)(?:\.[^.]+)?$', '\1') EndSwitch Switch $Arr Case 1 $FileList=StringSplit($FileList, @CRLF, 1) If @error And $FileList[1]='' Then Dim $FileList[1]=[0] Case 2 $FileList=StringSplit($FileList, @CRLF, 3) ; If @error And $FileList[0]='' Then SetError(3, 0, '') EndSwitch Return $FileList EndFunc ; поиск указанных типов файлов Func __FileSearch($Path, $Mask, $Include, $Level, $LD=0) Local $FileList='', $file, $s = FileFindFirstFile($Path&'\*') If $s = -1 Then Return '' While 1 $file = FileFindNextFile($s) If @error Then ExitLoop If @extended Then If $LD>=$Level Then ContinueLoop $LD+=1 $FileList&=__FileSearch($Path&'\'&$file, $Mask, $Include, $Level, $LD) $LD-=1 Else If StringInStr($Mask, ';'&StringRight($file, 4)&';') = $Include Then $FileList&=$Path&'\'&$file&@CRLF EndIf WEnd FileClose($s) Return $FileList EndFunc ; поиск по маске Func __FileSearchAll($Path, $Mask, $Level, $LD=0) Local $FileList='', $file, $s = FileFindFirstFile($Path&'\'&$Mask) If $s = -1 Then Return '' While 1 $file = FileFindNextFile($s) If @error Then ExitLoop If @extended Then If $LD>=$Level Then ContinueLoop $LD+=1 $FileList&=__FileSearchAll($Path&'\'&$file, $Mask, $Level, $LD) $LD-=1 Else $FileList&=$Path&'\'&$file&@CRLF EndIf WEnd FileClose($s) Return $FileList EndFunc |