Guest User

Untitled

a guest
Oct 16th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 5.50 KB | None | 0 0
  1. #include <Array.au3> ; для _ArrayDisplay
  2.  
  3. ; 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!
  4. ; все файлы папки WINDOWS в виде массива
  5. $timer = TimerInit()
  6. $FileList=_FileSearch(@WindowsDir, '*', True, 100)
  7. $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек'
  8.  
  9. _ArrayDisplay($FileList, $timer&' - все файлы')
  10. ; 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!
  11. ; только файлы exe и dll папки WINDOWS в виде списка
  12. $timer = TimerInit()
  13. $FileList=_FileSearch(@WindowsDir, 'exe;dll', True, 0, 1, 0)
  14. $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек'
  15. MsgBox(0, $timer&' - exe;dll', $FileList)
  16. ; 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!
  17. ; все файлы, кроме exe и dll папки WINDOWS в виде списка с относительными путями
  18. $timer = TimerInit()
  19. $FileList=_FileSearch(@WindowsDir, 'exe;dll', False, 0, 0, 0)
  20. $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек'
  21. MsgBox(0, $timer&' - кроме exe;dll', $FileList)
  22. ; 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!
  23. ; только файлы tmp и bak и gid папки WINDOWS в виде массива с относительными путями
  24. $timer = TimerInit()
  25. $FileList=_FileSearch(@WindowsDir, 'tmp;bak;gid', True, 100, 0)
  26. $timer = Round(TimerDiff($timer) / 1000, 2) & ' сек'
  27.  
  28. _ArrayDisplay($FileList, $timer&' - tmp;bak;gid')
  29. ; 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!
  30. ; Недопустимый символ в пути
  31. $FileList=_FileSearch('C:\WIN>DOWS', '*')
  32. If @error Then
  33.     MsgBox(0, 'Ошибка', 'Код ошибки: '&@error)
  34.     Exit
  35. EndIf
  36. ; 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!
  37.  
  38. ; ============================================================================================
  39. ; Function Name ...: _FileSearch (__FileSearch, __FileSearchAll)
  40. ; AutoIt Version ....: 3.2.12.1+
  41. ; Description ........: Поиск файлов по маске в подкаталогах.
  42. ; Parameters:
  43. ;       $Path - путь поиска
  44. ;       $Mask - маска, допустима обычная маска функции FileFindFirstFile, либо перечисление расширений через ";"
  45. ;       $exclude - (True / False) инвертировать маску, то есть исключить из поиска указанные типы файлов
  46. ;       $Level - (0-100) уровень вложенности (0 - корневой каталог)
  47. ;       $Full - 1 - полный путь, 0 - относительный
  48. ;       $Arr - 1 - результат в виде массива (по умолчанию), иное - список с разделителем @LF
  49. ;@error: 1 - неверный путь, 2 - неверная маска (проверка допустимых символов)
  50. ; Return values ....: Массив или список
  51. ; Author(s) ..........: AZJIO
  52. ; ============================================================================================
  53. ; функция проверки и подготовки входных параметров
  54. Func _FileSearch($Path, $Mask = '*', $exclude=True, $Level=100, $Full=1, $Arr=1)
  55.     Local $FileList
  56.     If Not StringRegExp($Path, '(?i)^[a-z]:[^/:*?"<>|]*$') Or StringInStr($Path, '\\') Then Return SetError(1)
  57.     If StringRight($Path, 1)='\' Then $Path=StringTrimRight($Path, 1)
  58.     If $Mask = '' Then $Mask = '*'
  59.     If StringInStr($Mask, '*') Or StringInStr($Mask, '?') Then
  60.         If StringRegExp($Mask, '[\\/:"<>|]') Then Return SetError(2)
  61.         $FileList=StringTrimRight(__FileSearchAll($Path, $Mask, $Level), 1)
  62.         If $Full = 0 Then $FileList=StringRegExpReplace($FileList, '(?m)^(?:.{'&StringLen($Path)+1&'})(.*)$', '\1')
  63.         If $Arr = 1 Then $FileList=StringSplit($FileList, @CRLF, 1)
  64.         Return $FileList
  65.     Else
  66.         If StringRegExp($Mask, '[\\/:*?"<>|]') Then Return SetError(2)
  67.         $Mask=';.'&StringReplace($Mask, ';', ';.')&';'
  68.         $FileList=StringTrimRight(__FileSearch($Path, $Mask, $exclude, $Level), 1)
  69.         If $Full = 0 Then $FileList=StringRegExpReplace($FileList, '(?m)^(?:.{'&StringLen($Path)+1&'})(.*)$', '\1')
  70.         If $Arr = 1 Then $FileList=StringSplit($FileList, @CRLF, 1)
  71.         Return $FileList
  72.     EndIf
  73. EndFunc
  74.  
  75. ; поиск указанных типов файлов
  76. Func __FileSearch($Path, $Mask, $exclude, $Level, $LD=0)
  77.     Local $FileList='', $file, $s = FileFindFirstFile($Path&'\*')
  78.     If $s = -1 Then Return ''
  79.     While 1
  80.         $file = FileFindNextFile($s)
  81.         If @error Then ExitLoop
  82.         If @extended Then
  83.             If $LD>=$Level Then ContinueLoop
  84.             $LD+=1
  85.             $FileList&=__FileSearch($Path&'\'&$file, $Mask, $exclude, $Level, $LD)
  86.             $LD-=1
  87.         Else
  88.             If StringInStr($Mask, ';'&StringRight($file, 4)&';') = $exclude Then $FileList&=$Path&'\'&$file&@CRLF
  89.         EndIf
  90.     WEnd
  91.     FileClose($s)
  92.     Return $FileList
  93. EndFunc
  94.  
  95. ; поиск по маске
  96. Func __FileSearchAll($Path, $Mask, $Level, $LD=0)
  97.     Local $FileList='', $file, $s = FileFindFirstFile($Path&'\'&$Mask)
  98.     If $s = -1 Then Return ''
  99.     While 1
  100.         $file = FileFindNextFile($s)
  101.         If @error Then ExitLoop
  102.         If @extended Then
  103.             If $LD>=$Level Then ContinueLoop
  104.             $LD+=1
  105.             $FileList&=__FileSearchAll($Path&'\'&$file, $Mask, $Level, $LD)
  106.             $LD-=1
  107.         Else
  108.             $FileList&=$Path&'\'&$file&@CRLF
  109.         EndIf
  110.     WEnd
  111.     FileClose($s)
  112.     Return $FileList
  113. EndFunc
Add Comment
Please, Sign In to add comment