I have made a combination from different solutions here in this forum (thanks to all inspirations)
_FileListToArrayEx is a full compatible _FileListToArray replacement with more speed and additional features
For AutoIt V3.3.0.0 replace @extended with StringInStr(FileGetAttrib($sPath & $sFile), "D")
(or comment lines with @extended and uncomment lines with StringInStr(FileGetAttrib($sPath & $sFile), "D"))
The speed is better then _FileListToArray (non recursiv) and mostly better than other recursiv FileListToArray solutions
PS: I have added a function for creating a files and folders test structure, so everyone can test with the same basics.
#include <Array.au3>
#include <File.au3>
;Here you can create a file and folder structure for testing (9072 files, 780 folders)
;CreateTestFileFolders("D:\Temp\Test")
;-------------------
;Testing parameters
Dim $Repeat = 1
;Dim $Repeat = 100
Dim $SearchPath = "D:\Temp\Test"
;Dim $SearchPath = "C:\Windows\System32"
Dim $Pattern = "*"
;Dim $Pattern = "*.dll"
Dim $Flag = 0
;Dim $Flag = 0 + 4
Dim $Exclude = ""
;Dim $Exclude = "*.txt;*.sys;*.dat;*äöü*"
Dim $Recursiv = False
;Dim $Recursiv = True
;Test-Start##########################################
;_FileListToArray
$TimeBegin = TimerInit()
For $TCount = 1 To $Repeat
$aRet = _FileListToArray($SearchPath, $Pattern, 0)
Next
$TimeDiff = StringFormat("Sec = %.2f", TimerDiff($TimeBegin) / 1000)
ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & " - _FileListToArray: " & $TimeDiff & " , " & $aRet[0] & @LF) ;#KBM
;_ArrayDisplay($aRet, '')
;_FileListToArrayEx
$TimeBegin = TimerInit()
For $TCount = 1 To $Repeat
$aRet = _FileListToArrayEx
($SearchPath, $Pattern, $Flag, $Recursiv, $Exclude, 1)
Next
$TimeDiff = StringFormat("Sec = %.2f", TimerDiff($TimeBegin) / 1000)
ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & " - _FileListToArrayEx: " & $TimeDiff & " , " & $aRet[0] & @LF) ;#KBM
;_ArrayDisplay($aRet, '')
;********************************************************************
; #FUNCTION# =====================================================
; Name: _FileListToArrayEx
; Description: full compatible _FileListToArray replacement (with more speed and additional features)
; additional: multi-path, multi-filter, multi exclude-filter, recursiv search
; optional full pathname
; Syntax: _FileListToArrayEx([$sPath = @ScriptDir, [$sFilter = "*", [$iFlag = 0, [$bRecursiv = False, [$sExclude = "", [$iFormat = 1]]]]]])
; Parameter(s): $sPath = optional: path to generate filelist for, multi paths separated with semicolon (ex: "C:\";D:\Temp")
; if no path is given then @ScriptDir is used
; $sFilter = optional: The filter to use. (default: "*")
; multi filters separated with semicolon (ex: *.exe; *.txt will find all .exe and .txt files)
; (Search the Autoit3 manual for the word "WildCards" for details)
; $iFlag = Optional: specifies whether to return files, folders or both
; 0 = (Default) Return both files and folders
; 1 = Return files only
; 2 = Return folders only
; $iFlag + 4 = Return Filenames and/or Folders incl full Path
; $bRecursiv = optional: true: recursive search in rootdir and subdirs
; False (default): search only in rootdir
; $sExclude = optional: exclude a file from the list by all or part of its name, various statements delimited with semicolon
; (ex: Unins* will remove all files/folders that start with Unins)
; $iFormat = optional: return format
; 0 = String ( "|" delimited)
; 1 = (default) one-dimensional array, array[0] = number of files\folders returned
; 2 = one-dimensional array, 0-based
; Requirement(s): none
; Return Value(s): on success: string or array (dependent on $iFormat)
; Author(s): bernd670, Tlem, Spiff59, Zedna, KaFu, SmOke_N, GEOSoft, BaKaMu
; ===================================================================
Func _FileListToArrayEx
($sPath = @ScriptDir, $sFilter = "*", $iFlag = 0, $bRecursiv = False, $sExclude = "", $iFormat = 1)
Local $hSearch, $iPCount, $iFCount, $sFile, $TFlag = 0, $sFileList = ""
If $sPath = -1 Or $sPath = Default Then $sPath = @ScriptDir
If $sFilter = -1 Or $sFilter = Default Then $sFilter = "*"
If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
If $bRecursiv = Default Then $bRecursiv = False
If $sExclude = -1 Or $sExclude = Default Then $sExclude = ""
If $iFormat = -1 Or $iFormat = Default Then $iFormat = 1
;separate multi path
Local $aPath = StringSplit($sPath, ';')
;separate multi filter
Local $aFilter = StringSplit($sFilter, ';')
For $iPCount = 1 To $aPath[0]
Local $sPathItem = StringStripWS($aPath[$iPCount], 3) ;Strip leading and trailing spaces
Local $sDelim = "|"
If StringRight($sPathItem, 1) <> "\" Then $sPathItem = $sPathItem & "\" ;check for trailing "\"
;return full-path or filename only ($iFlag 0,1,2 = Filename, $iFlag 4,5,6 = full path)
If $iFlag > 3 Then
$sDelim &= $sPathItem
$TFlag = $iFlag - 4
Else
$TFlag = $iFlag
EndIf
;perform the search
For $iFCount = 1 To $aFilter[0]
Local $FilterItem = StringStripWS($aFilter[$iFCount], 3) ;Strip leading and trailing spaces
If StringRegExp($FilterItem, "[\\/:<>|]") Then ContinueLoop ;Look for bad chars
$hSearch = FileFindFirstFile($sPathItem & $FilterItem)
If @error Then ContinueLoop
Switch $TFlag
Case 0 ;Files and Folders
While True
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
$sFileList &= $sDelim & $sFile
WEnd
Case 1 ;Files Only
While True
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
;If StringInStr(FileGetAttrib($sPath & $sFile), "D") <> 0 Then ContinueLoop; bypass folder (ver 3.3.0.0)
If @extended Then ContinueLoop ;bypass folder (for Autoit versions > 3.3.0.0)
$sFileList &= $sDelim & $sFile
WEnd
Case 2 ;Folders Only
While True
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
;If StringInStr(FileGetAttrib($sPath & $sFile), "D") = 0 Then ContinueLoop; bypass file (ver 3.3.0.0)
If @extended = 0 Then ContinueLoop ;bypass file (for Autoit versions > 3.3.0.0)
$sFileList &= $sDelim & $sFile
WEnd
Case Else
Return SetError(3, 3, "")
EndSwitch
FileClose($hSearch)
Next
;---------------
;optional do a recursive search
If $bRecursiv Then
$hSearch = FileFindFirstFile($sPathItem & "*.*")
If Not @error Then
While True
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
;If StringInStr(FileGetAttrib($sPath & $sFile), "D") = 0 Then ContinueLoop; bypass file (ver 3.3.0.0)
If @extended = 0 Then ContinueLoop ;bypass file (for Autoit versions > 3.3.0.0)
$sFileList &= _FileListToArrayEx
($sPathItem & $sFile, $sFilter, $iFlag, $bRecursiv, "", 0)
WEnd
FileClose($hSearch)
EndIf
EndIf
Next ;$iPCount
;---------------
;optional exclude filename/folder
If $sExclude Then ;will be executed only once (at the end)
Local $aFilesFound = StringSplit(StringTrimLeft($sFileList, 1), "|", 0)
;Strip leading and trailing spaces and spaces between semi colon delimiter
$sExclude = StringStripWS(StringRegExpReplace($sExclude, "\s*;\s*", ";"), 3)
;convert $sExclude to RegExp formated string
$sExclude = StringReplace($sExclude, ".", "\.")
$sExclude = StringReplace($sExclude, "?", ".")
$sExclude = StringReplace($sExclude, "*", ".*?")
$sExclude = StringReplace($sExclude, ";", "|")
$sFileList = ""
;Compare Filenames with $sExclude
For $iFCount = 1 To $aFilesFound[0]
If StringRegExp(StringRegExpReplace($aFilesFound[$iFCount], "(.*?[\\/]+)*(.*?\z)", "\2"), "(?i)\A" & $sExclude & "\z") Then ContinueLoop
$sFileList &= "|" & $aFilesFound[$iFCount]
Next
EndIf
;---------------
;Set according return value
Switch $iFormat
Case 0
Return $sFileList
Case 1
If $sFileList = "" Then
Local $aRet[1] = [0]
Return $aRet
Else
Return StringSplit(StringTrimLeft($sFileList, 1), "|", $iFormat)
EndIf
Case 2
If $sFileList = "" Then
Return ""
Else
Return StringSplit(StringTrimLeft($sFileList, 1), "|", $iFormat)
EndIf
EndSwitch
EndFunc ;==>_FileListToArrayEx
;Create test files and folders (9072 files, 780 folders) ---------------------------------
Func CreateTestFileFolders
($RootPath)
Local $Dir0 = $RootPath
DirCreate($Dir0)
Local $File0 = "File-Root"
For $FCount = 1 To 2
$hFile = FileOpen($Dir0 & "\" & $File0 & "(" & $FCount & ").txt", 1)
FileClose($hFile)
$hFile = FileOpen($Dir0 & "\" & $File0 & "(" & $FCount & ").dat", 1)
FileClose($hFile)
$hFile = FileOpen($Dir0 & "\" & $File0 & "äöü(" & $FCount & ").ß~°²³", 1)
FileClose($hFile)
$hFile = FileOpen($Dir0 & "\" & $File0 & "(" & $FCount & ").hid", 1)
FileSetAttrib($Dir0 & "\" & $File0 & "(" & $FCount & ").hid", "+H", 0)
FileClose($hFile)
$hFile = FileOpen($Dir0 & "\" & $File0 & "(" & $FCount & ").sys", 1)
FileSetAttrib($Dir0 & "\" & $File0 & "(" & $FCount & ").sys", "+S", 0)
FileClose($hFile)
$hFile = FileOpen($Dir0 & "\" & $File0 & "(" & $FCount & ").rsh", 1)
FileSetAttrib($Dir0 & "\" & $File0 & "(" & $FCount & ").rsh", "+R+S+H", 0)
FileClose($hFile)
Next
For $Count1 = 1 To 5
Local $Dir1 = $Dir0 & "\" & "Dir-" & $Count1
DirCreate($Dir1)
Local $File1 = "File-" & $Count1
For $FCount = 1 To 2
$hFile = FileOpen($Dir1 & "\" & $File1 & "(" & $FCount & ").txt", 1)
FileClose($hFile)
$hFile = FileOpen($Dir1 & "\" & $File1 & "(" & $FCount & ").dat", 1)
FileClose($hFile)
$hFile = FileOpen($Dir1 & "\" & $File1 & "äöü(" & $FCount & ").ß~°²³", 1)
FileClose($hFile)
$hFile = FileOpen($Dir1 & "\" & $File1 & "(" & $FCount & ").hid", 1)
FileSetAttrib($Dir1 & "\" & $File1 & "(" & $FCount & ").hid", "+H", 0)
FileClose($hFile)
$hFile = FileOpen($Dir1 & "\" & $File1 & "(" & $FCount & ").sys", 1)
FileSetAttrib($Dir1 & "\" & $File1 & "(" & $FCount & ").sys", "+S", 0)
FileClose($hFile)
$hFile = FileOpen($Dir1 & "\" & $File1 & "(" & $FCount & ").rsh", 1)
FileSetAttrib($Dir1 & "\" & $File1 & "(" & $FCount & ").rsh", "+R+S+H", 0)
FileClose($hFile)
Next
For $Count2 = 1 To 5
Local $Dir2 = $Dir1 & "\" & "Dir-" & $Count1 & $Count2
DirCreate($Dir2)
For $Count3 = 1 To 5
Local $Dir3 = $Dir2 & "\" & "Dir-" & $Count1 & $Count2 & $Count3
DirCreate($Dir3)
Local $File3 = "File-" & $Count1 & $Count2 & $Count3
For $FCount = 1 To 2
$hFile = FileOpen($Dir3 & "\" & $File3 & "(" & $FCount & ").txt", 1)
FileClose($hFile)
$hFile = FileOpen($Dir3 & "\" & $File3 & "(" & $FCount & ").dat", 1)
FileClose($hFile)
$hFile = FileOpen($Dir3 & "\" & $File3 & "äöü(" & $FCount & ").ß~°²³", 1)
FileClose($hFile)
$hFile = FileOpen($Dir3 & "\" & $File3 & "(" & $FCount & ").hid", 1)
FileSetAttrib($Dir3 & "\" & $File3 & "(" & $FCount & ").hid", "+H", 0)
FileClose($hFile)
$hFile = FileOpen($Dir3 & "\" & $File3 & "(" & $FCount & ").sys", 1)
FileSetAttrib($Dir3 & "\" & $File3 & "(" & $FCount & ").sys", "+S", 0)
FileClose($hFile)
$hFile = FileOpen($Dir3 & "\" & $File3 & "(" & $FCount & ").rsh", 1)
FileSetAttrib($Dir3 & "\" & $File3 & "(" & $FCount & ").rsh", "+R+S+H", 0)
FileClose($hFile)
Next
For $Count4 = 1 To 5
Local $Dir4 = $Dir3 & "\" & "Dir-" & $Count1 & $Count2 & $Count3 & $Count4
DirCreate($Dir4)
Local $File4 = "File-" & $Count1 & $Count2 & $Count3 & $Count4
For $FCount = 1 To 2
$hFile = FileOpen($Dir4 & "\" & $File4 & "(" & $FCount & ").txt", 1)
FileClose($hFile)
$hFile = FileOpen($Dir4 & "\" & $File4 & "(" & $FCount & ").dat", 1)
FileClose($hFile)
$hFile = FileOpen($Dir4 & "\" & $File4 & "äöü(" & $FCount & ").ß~°²³", 1)
FileClose($hFile)
$hFile = FileOpen($Dir4 & "\" & $File4 & "(" & $FCount & ").hid", 1)
FileSetAttrib($Dir4 & "\" & $File4 & "(" & $FCount & ").hid", "+H", 0)
FileClose($hFile)
$hFile = FileOpen($Dir4 & "\" & $File4 & "(" & $FCount & ").sys", 1)
FileSetAttrib($Dir4 & "\" & $File4 & "(" & $FCount & ").sys", "+S", 0)
FileClose($hFile)
$hFile = FileOpen($Dir4 & "\" & $File4 & "(" & $FCount & ").rsh", 1)
FileSetAttrib($Dir4 & "\" & $File4 & "(" & $FCount & ").rsh", "+R+S+H", 0)
FileClose($hFile)
Next
Next
Next
Next
Next
EndFunc ;==>CreateTestFileFolders