Jump to content



Photo

RecFileListToArray - New Version 2 Dec 12


  • Please log in to reply
255 replies to this topic

#1 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 05 March 2011 - 02:56 PM

New Version - 2 Dec 2012

Changed: The Include_List/Exclude_List/Exclude_Folder_List parameters are now incorporated into a single parameter - the different elements being separated by " | ". So the syntax becomes simpler as you no longer need to add the intervening parameters if they are set to the default values:
; Old syntax: $aList = _RecFileListToArray($sPath, "*.*", 0, 1, 0, 1, "*.bat;*.ini", "temp*") ; New syntax: $aList = _RecFileListToArray($sPath, "*.*|*.bat;*.ini|temp*", 0, 1)

Both will search recursively for all files in the tree, ignoring any folders beginning with "temp" and excluding all bat and ini files, and returning a non-sorted list with relative paths.

Note: This syntax change is not script-breaking. The original syntax with separate parameters will still be honoured, but any exclude information added within the initial parameter will override the originals:
; This will honour the existing exclude parameters $aList = _RecFileListToArray($sPath, "*.*", 0, 1, 0, 1, "*.bat;*.ini", "temp*") ; This will not as blank sections have been added to the first parameter $aList = _RecFileListToArray($sPath, "*.*||", 0, 1, 0, 1, "*.bat;*.ini", "temp*")

So there is no need to amend your current scripts - but altering them is not too difficult if you decide to do so. ;)

A reminder of how the UDF interprets the various include/exclude options:
Spoiler


Previous release information:
Spoiler


Here is the current version of my RecFileListToArray UDF. With it you can:

- Search within a folder and its subfolders to a specified level (which includes not looking into subfolders at all or going as deep as they are nested)

- Use multiple masks to include/exclude particular file/folder names and extensions

- Look for files and/or folders - and easily distinguish between folders and files in the returned array

- Sort the results alphabetically within alphabetically sorted subfolders

- Choose the level of path information included (full, relative, none)

- NEW Omit hidden and/or system files/folders and link/junction folders from the return


The syntax is compatible with the existing _FileListToArray, so you can use this UDF in its place should you wish to have just the one function.

New Here is a short example to give you an idea of what it can do:
AutoIt         
#include <Array.au3> #include "RecFileListToArray.au3" Global $sAutoItDir = StringReplace(StringReplace(@AutoItExe, "AutoIt3.exe", ""), "beta", "") & "" ConsoleWrite($sAutoItDir & @CRLF) ; A sorted list of all files and folders in the AutoIt installation $aArray = _RecFileListToArray($sAutoItDir, "*", 0, 1, 1) ConsoleWrite("Error: " & @error & " - " & " Extended: " &  @extended & @CRLF) _ArrayDisplay($aArray, "Sorted tree") ; A non-sorted list of all but the .exe files in the AutoIt3 folder $aArray = _RecFileListToArray($sAutoItDir, "*|*.exe", 1, 0, 1, 0) ConsoleWrite("Error: " & @error & " - " & " Extended: " &  @extended & @CRLF) _ArrayDisplay($aArray, "Non .EXE files") ; And here are the .exe files we left out last time $aArray = _RecFileListToArray($sAutoItDir, "*.exe", 1) ConsoleWrite("Error: " & @error & " - " & " Extended: " &  @extended & @CRLF) _ArrayDisplay($aArray, ".EXE Files") ; A test for all folders and .exe files only throughout the folder tree, omitting folders beginning with I (Icons and Include) $aArray = _RecFileListToArray($sAutoItDir, "*.exe||I*", 0, 1, 1) ConsoleWrite("Error: " & @error & " - " & " Extended: " &  @extended & @CRLF) _ArrayDisplay($aArray, "Recur with filter") ; And to show that the filter applies to folders when not recursive $aArray = _RecFileListToArray($sAutoItDir, "*.exe", 0, 0, 1) ConsoleWrite("Error: " & @error & " - " & " Extended: " &  @extended & @CRLF) _ArrayDisplay($aArray, "Non-recur with filter") ; The filter also applies to folders when recursively searching for folders $aArray = _RecFileListToArray($sAutoItDir, "Icons", 2, 1) ConsoleWrite("Error: " & @error & " - " & " Extended: " &  @extended & @CRLF) _ArrayDisplay($aArray, "Folder recur with filter") ; The root of C:Windows showing hidden/system folders $aArray = _RecFileListToArray("C:Windows", "*", 2) ConsoleWrite("Error: " & @error & " - " & " Extended: " &  @extended & @CRLF) _ArrayDisplay($aArray, "Show hidden folders") ; The root of C:Windows omitting hidden/system folders $aArray = _RecFileListToArray("C:Windows", "*", 2 + 4 + 8) ConsoleWrite("Error: " & @error & " - " & " Extended: " &  @extended & @CRLF) _ArrayDisplay($aArray, "Show hidden folders")

New And here is the UDF itself:
AutoIt         
#include-once ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; #INDEX# ======================================================================================================================= ; Title .........: _RecFileListToArray ; AutoIt Version : v3.3.1.1 or higher ; Language ......: English ; Description ...: Lists files and\or folders in specified path with optional recursion to defined level and result sorting ; Note ..........: ; Author(s) .....: Melba23 ; Remarks .......: - Modified Array.au3 functions - credit: Jos van der Zande, LazyCoder, Tylo, Ultima, SolidSnake and gcriaco ;                  - SRE patterns - credit: various forum members and Spiff59 in particular ;                  - DllCall code suggestion - credit: guinness ;                  - Despite the name, this UDF is iterative, not recursive ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _RecFileListToArray: Lists files and\or folders in a specified path with optional recursion to defined level and result sorting ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _RFLTA_ListToMask ......; Convert include/exclude lists to SRE format ; _RFLTA_AddToList .......; Add element to list which is resized if necessary ; _RFLTA_AddFileLists ....; Add internal lists after resizing and optional sorting ; _RFLTA_FileListSearch ..; Search file match list for files associated with a folder ; _RFLTA_ArraySort .......; Wrapper for QuickSort function ; _RFLTA_QuickSort .......: Recursive array sort ; _RFLTA_ArrayConcatenate : Join 2 arrays ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _RecFileListToArray ; Description ...: Lists files and\or folders in a specified path with optional recursion to defined level and result sorting ; Syntax.........: _RecFileListToArray($sPath[, $sMask = "*"[, $iReturn = 0[, $iRecur = 0[, $iSort = 0[, $iReturnPath = 1[, $sExclude_List = ""[, $sExclude_List_Folder]]]]]]]) ; Parameters ....: $sPath - Initial path used to generate filelist.  If path ends in \ then folders will be returned with an ending \ ;                  $sMask - Optional: Filter for result. Multiple filters must be separated by ";" ;                           Use "|" to separate 3 possible sets of filters: "Include|Exclude|Exclude_Folders" ;                               Include = Files/Folders to include (default = "*" [all]) ;                               Exclude = Files/Folders to exclude (default = "" [none]) ;                               Exclude_Folders = only used if basic $iReturn = 0 AND $iRecur = 1 to exclude defined folders (default = "" [none]) ;                  $iReturn - Optional: specifies whether to return files, folders or both and omits those with certain attributes ;                              0 - Return both files and folders (Default) ;                                   If non-recursive Include/Exclude_List applies to files and folders ;                                   If recursive Include/Exclude_List applies to files only, all folders are searched unless excluded using $sExclude_List_Folder ;                              1 - Return files only    - Include/Exclude_List applies to files only, all folders searched if recursive ;                              2 - Return folders only  - Include/Exclude_List applies to folders only for searching and return ;                                   Add one or more of the following to $iReturn to omit files/folders with that attribute ;                                   + 4  - Hidden files and folders ;                                   + 8  - System files and folders ;                                   + 16 - Link/junction folders ;                                   Note:  Omitting files/folders uses a different search algorithm and takes approx 50% longer ;                  $iRecur - Optional: specifies whether to search recursively in subfolders and to what level ;                             1 - Search in all subfolders (unlimited recursion) ;                             0 - Do not search in subfolders (Default) ;                             Negative integer - Search in subfolders to specified depth ;                  $iSort - Optional: sort ordered in alphabetical and depth order ;                             0 - Not sorted (Default) ;                             1 - Sorted ;                             2 - Sorted with faster algorithm (assumes files sorted within each folder - requires NTFS drive) ;                  $iReturnPath - Optional: specifies displayed path of results ;                             0 - File/folder name only ;                             1 - Relative to initial path (Default) ;                             2 - Full path included ; ; [These parameters are now deprecated as they should be included within the $sMask parameter] ; [If $sMask contains sections for Exclude and Exclude_Folders (i.e "|" characters are used) then these parameters will be ignored] ;                  $sExclude_List - Optional: filter for excluded results (default ""). Multiple filters must be separated by ";" ;                  $sExclude_List_Folder - Optional: only used if $iReturn = 0 AND $iRecur = 1 to exclude folders matching the filter ; ; Requirement(s).: v3.3.1.1 or higher ; Return values .: Success: One-dimensional array made up as follows: ;                            [0] = Number of Files\Folders returned ;                            [1] = 1st File\Folder ;                            [2] = 2nd File\Folder ;                            ... ;                            [n] = nth File\Folder ;                    Failure: Null string and @error = 1 with @extended set as follows: ;                            1 = Path not found or invalid ;                            2 = Invalid $sInclude_List ;                            3 = Invalid $iReturn ;                            4 = Invalid $iRecur ;                            5 = Invalid $iSort ;                            6 = Invalid $iReturnPath ;                            7 = Invalid $sExclude_List ;                            8 = Invalid $sExclude_List_Folder ;                            9 = No files/folders found ; Author ........: Melba23 ; Remarks .......: Compatible with existing _FileListToArray syntax ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _RecFileListToArray($sInitialPath, $sMask = "*", $iReturn = 0, $iRecur = 0, $iSort = 0, $iReturnPath = 1, $sExclude_List = "", $sExclude_List_Folder = "")     Local $asReturnList[100] = [0], $asFileMatchList[100] = [0], $asRootFileMatchList[100] = [0], $asFolderMatchList[100] = [0], $asFolderSearchList[100] = [1]     Local $sFolderSlash = "", $iMaxLevel, $sInclude_List, $sInclude_File_Mask, $sExclude_File_Mask, $sInclude_Folder_Mask = ".+", $sExclude_Folder_Mask = ":"     Local $hSearch, $fFolder, $sRetPath = "", $sCurrentPath, $sName, $iAttribs, $iHide_HS = 0, $iHide_Link = 0     Local $asFolderFileSectionList[100][2] = [[0, 0]], $sFolderToFind, $iFileSectionstartIndex, $iFileSectionendIndex     ; Check for valid path     If Not FileExists($sInitialPath) Then Return SetError(1, 1, "")     ; Check if folders should have trailing \ and ensure that initial path does have one     If StringRight($sInitialPath, 1) = "\" Then         $sFolderSlash = "\"     Else         $sInitialPath = $sInitialPath & "\"     EndIf     ; Add path to folder search list     $asFolderSearchList[1] = $sInitialPath     ; Check for H or S omitted     If BitAnd($iReturn, 4) Then         $iHide_HS += 2         $iReturn -= 4     EndIf     If BitAnd($iReturn, 8) Then         $iHide_HS += 4         $iReturn -= 8     EndIf     ; Check for link/junction omitted     If BitAnd($iReturn, 16) Then         $iHide_HS = 0x406         $iReturn -= 16     EndIf     ; Check for valid recur value     If $iRecur > 1 Or Not IsInt($iRecur) Then Return SetError(1, 4, "")     ; If required, determine \ count for max recursive level setting     If $iRecur < 0 Then         StringReplace($sInitialPath, "\", "", 2)         $iMaxLevel = @extended - $iRecur     EndIf     ; Check mask parameter     Local $aMaskSplit = StringSplit($sMask, "|")     ; Check for multiple sections and set values     Switch $aMaskSplit[0]         Case 3             $sExclude_List_Folder = $aMaskSplit[3]             ContinueCase         Case 2             $sExclude_List = $aMaskSplit[2]             ContinueCase         Case 1             $sInclude_List = $aMaskSplit[1]     EndSwitch     ; Create Include mask for files     If $sInclude_List = "*" Then         $sInclude_File_Mask = ".+"     Else         If Not _RFLTA_ListToMask($sInclude_File_Mask, $sInclude_List) Then Return SetError(1, 2, "")     EndIf     ; Set Include mask for folders     Switch $iReturn         Case 0             ; Folders affected by mask if not recursive             Switch $iRecur                 Case 0                     ; Folders match mask for compatibility                     $sInclude_Folder_Mask = $sInclude_File_Mask                 ;Case Else                     ; All folders match             EndSwitch         ;Case 1             ; All folders match         Case 2             ; Folders affected by mask             $sInclude_Folder_Mask = $sInclude_File_Mask     EndSwitch     ; Create Exclude List mask for files     If $sExclude_List = "" Then         $sExclude_File_Mask = ":" ; Set unmatchable mask     Else         If Not _RFLTA_ListToMask($sExclude_File_Mask, $sExclude_List) Then Return SetError(1, 7, "")     EndIf     ; Set Exclude mask for folders     Switch $iReturn         Case 0             ; Folders affected by mask if not recursive             Switch $iRecur                 Case 0                     ; Folders match mask for compatibility                     $sExclude_Folder_Mask = $sExclude_File_Mask                 Case Else                     ; Exclude defined folders as set in extended                     If $sExclude_List_Folder <> "" Then                         If Not _RFLTA_ListToMask($sExclude_Folder_Mask, $sExclude_List_Folder) Then Return SetError(1, 8, "")                     EndIf             EndSwitch         ;Case 1             ; All folders match         Case 2             ; Folders affected by normal mask             $sExclude_Folder_Mask = $sExclude_File_Mask     EndSwitch     ; Verify other parameters     If Not ($iReturn = 0 Or $iReturn = 1 Or $iReturn = 2) Then Return SetError(1, 3, "")     If Not ($iSort = 0 Or $iSort = 1 Or $iSort = 2) Then Return SetError(1, 5, "")     If Not ($iReturnPath = 0 Or $iReturnPath = 1 Or $iReturnPath = 2) Then Return SetError(1, 6, "")     ; Prepare for DllCall if required     If $iHide_HS Or $iHide_Link Then         Local $tFile_Data = DllStructCreate("struct;align 4;dword FileAttributes;uint64 CreationTime;uint64 LastAccessTime;uint64 LastWriteTime;" & _                             "dword FileSizeHigh;dword FileSizeLow;dword Reserved0;dword Reserved1;wchar FileName[260];wchar AlternateFileName[14];endstruct")         Local $pFile_Data = DllStructGetPtr($tFile_Data), $hDLL = DllOpen('kernel32.dll'), $aDLL_Ret     EndIf     ; Search within listed folders     While $asFolderSearchList[0] > 0         ; Set path to search         $sCurrentPath = $asFolderSearchList[$asFolderSearchList[0]]         ; Reduce folder search list count         $asFolderSearchList[0] -= 1         ; Determine return path to add to file/folder name         Switch $iReturnPath             ; Case 0 ; Name only                 ; Leave as ""             Case 1 ;Relative to initial path                 $sRetPath = StringReplace($sCurrentPath, $sInitialPath, "")             Case 2 ; Full path                 $sRetPath = $sCurrentPath         EndSwitch         ; Get search handle - use code matched to required listing         If $iHide_HS Or $iHide_Link Then             ; Use DLL code             $aDLL_Ret = DllCall($hDLL, 'ptr', 'FindFirstFileW', 'wstr', $sCurrentPath & "*", 'ptr', $pFile_Data)             If @error Or Not $aDLL_Ret[0] Then                 ContinueLoop             EndIf             $hSearch = $aDLL_Ret[0]         Else             ; Use native code             $hSearch = FileFindFirstFile($sCurrentPath & "*")             ; If folder empty move to next in list             If $hSearch = -1 Then                 ContinueLoop             EndIf         EndIf         ; If sorting files and folders with paths then store folder name and position of associated files in list         If $iReturn = 0 And $iSort And $iReturnPath Then             _RFLTA_AddToList($asFolderFileSectionList, $sRetPath, $asFileMatchList[0] + 1)         EndIf         ; Search folder - use code matched to required listing         While 1             ; Use DLL code             If $iHide_HS Or $iHide_Link Then                 ; Use DLL code                 $aDLL_Ret = DllCall($hDLL, 'int', 'FindNextFileW', 'ptr', $hSearch, 'ptr', $pFile_Data)                 ; Check for end of folder                 If @error Or Not $aDLL_Ret[0] Then                     ExitLoop                 EndIf                 ; Extract data                 $sName = DllStructGetData($tFile_Data, "FileName")                 ; Check for .. return - only returned by the DllCall                 If $sName = ".." Then                     ContinueLoop                 EndIf                 $iAttribs = DllStructGetData($tFile_Data, "FileAttributes")                 ; Check for hidden/system attributes and skip if found                 If $iHide_HS And BitAnd($iAttribs, $iHide_HS) Then                     ContinueLoop                 EndIf                 ; Check for link attribute and skip if found                 If $iHide_Link And BitAnd($iAttribs, $iHide_Link) Then                     ContinueLoop                 EndIf                 ; Set subfolder flag                 $fFolder = 0                 If BitAnd($iAttribs, 16) Then                     $fFolder = 1                 EndIf             Else                 ; Use native code                 $sName = FileFindNextFile($hSearch)                 ; Check for end of folder                 If @error Then                     ExitLoop                 EndIf                 ; Set subfolder flag - @extended set in 3.3.1.1 +                 $fFolder = @extended             EndIf             ; If folder then check whether to add to search list             If $fFolder Then                 Select                     Case $iRecur < 0 ; Check recur depth                         StringReplace($sCurrentPath, "\", "", 0, 2)                         If @extended < $iMaxLevel Then                             ContinueCase ; Check if matched to masks                         EndIf                     Case $iRecur = 1 ; Full recur                         If Not StringRegExp($sName, $sExclude_Folder_Mask) Then ; Add folder unless excluded                             _RFLTA_AddToList($asFolderSearchList, $sCurrentPath & $sName & "\")                         EndIf                     ; Case $iRecur = 0 ; Never add                         ; Do nothing                 EndSelect             EndIf             If $iSort Then ; Save in relevant folders for later sorting                 If $fFolder Then                     If StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then                         _RFLTA_AddToList($asFolderMatchList, $sRetPath & $sName & $sFolderSlash)                     EndIf                 Else                     If StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then                         ; Select required list for files                         If $sCurrentPath = $sInitialPath Then                             _RFLTA_AddToList($asRootFileMatchList, $sRetPath & $sName)                         Else                             _RFLTA_AddToList($asFileMatchList, $sRetPath & $sName)                         EndIf                     EndIf                 EndIf             Else ; Save directly in return list                 If $fFolder Then                     If $iReturn <> 1 And StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then                         _RFLTA_AddToList($asReturnList, $sRetPath & $sName & $sFolderSlash)                     EndIf                 Else                     If $iReturn <> 2 And StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then                         _RFLTA_AddToList($asReturnList, $sRetPath & $sName)                     EndIf                 EndIf             EndIf         WEnd         ; Close current search         FileClose($hSearch)     WEnd     ; Close the DLL if needed     If $iHide_HS Then         DllClose($hDLL)     EndIf     If $iSort Then         ; Check if any file/folders have been added depending on required return         Switch $iReturn             Case 0 ; If no folders then number of files is immaterial                 If $asRootFileMatchList[0] = 0 And $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "")             Case 1                 If $asRootFileMatchList[0] = 0 And $asFileMatchList[0] = 0 Then Return SetError(1, 9, "")             Case 2                 If $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "")         EndSwitch         Switch $iReturn             Case 2 ; Folders only                 ; Correctly size folder match list                 ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]                 ; Copy size folder match array                 $asReturnList = $asFolderMatchList                 ; Simple sort list                 _RFLTA_ArraySort($asReturnList)             Case 1 ; Files only                 If $iReturnPath = 0 Then ; names only so simple sort suffices                     ; Combine file match lists                     _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)                     ; Simple sort combined file list                     _RFLTA_ArraySort($asReturnList)                 Else                     ; Combine sorted file match lists                     _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList, 1)                 EndIf             Case 0 ; Both files and folders                 If $iReturnPath = 0 Then ; names only so simple sort suffices                     ; Combine file match lists                     _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)                     ; Set correct count for folder add                     $asReturnList[0] += $asFolderMatchList[0]                     ; Resize and add file match array                     ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]                     _RFLTA_ArrayConcatenate($asReturnList, $asFolderMatchList)                     ; Simple sort final list                     _RFLTA_ArraySort($asReturnList)                 Else                     ; Size return list                     Local $asReturnList[$asFileMatchList[0] + $asRootFileMatchList[0] + $asFolderMatchList[0] + 1]                     $asReturnList[0] = $asFileMatchList[0] + $asRootFileMatchList[0] + $asFolderMatchList[0]                     ; Sort root file list                     _RFLTA_ArraySort($asRootFileMatchList, 1, $asRootFileMatchList[0])                     ; Add the sorted root files at the top                     For $i = 1 To $asRootFileMatchList[0]                         $asReturnList[$i] = $asRootFileMatchList[$i]                     Next                     ; Set next insertion index                     Local $iNextInsertionIndex = $asRootFileMatchList[0] + 1                     ; Sort folder list                     _RFLTA_ArraySort($asFolderMatchList, 1, $asFolderMatchList[0])                     ; Work through folder list                     For $i = 1 To $asFolderMatchList[0]                         ; Format folder name for search                         If $sFolderSlash Then                             $sFolderToFind = $asFolderMatchList[$i]                         Else                             $sFolderToFind = $asFolderMatchList[$i] & "\"                         EndIf                         ; Find folder in FolderFileSectionList                         For $j = 1 To $asFolderFileSectionList[0][0]                             If $sFolderToFind = $asFolderFileSectionList[$j][0] Then ExitLoop                         Next                         ; Set file list indexes                         $iFileSectionstartIndex = $asFolderFileSectionList[$j][1]                         If $j = $asFolderFileSectionList[0][0] Then                             $iFileSectionendIndex = $asFileMatchList[0]                         Else                             $iFileSectionendIndex = $asFolderFileSectionList[$j + 1][1] - 1                         EndIf                         ; Sort files if required                         ;If $iSort = 1 Then                             _RFLTA_ArraySort($asFileMatchList, $iFileSectionstartIndex, $iFileSectionendIndex)                         ;EndIf                         ; Add folder to return list                         $asReturnList[$iNextInsertionIndex] = $asFolderMatchList[$i]                         $iNextInsertionIndex += 1                         ; Add files to return list                         For $j = $iFileSectionstartIndex To $iFileSectionendIndex                             $asReturnList[$iNextInsertionIndex] = $asFileMatchList[$j]                             $iNextInsertionIndex += 1                         Next                     Next                 EndIf         EndSwitch     Else ; No sort         ; Check if any file/folders have been added         If $asReturnList[0] = 0 Then Return SetError(1, 9, "")         ; Remove any unused return list elements from last ReDim         ReDim $asReturnList[$asReturnList[0] + 1]     EndIf     Return $asReturnList EndFunc   ;==>_RecFileListToArray ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_ListToMask ; Description ...: Convert include/exclude lists to SRE format ; Syntax ........: _RFLTA_ListToMask(ByRef $sMask, $sList) ; Parameters ....: $asMask - Include/Exclude mask to create ;                  $asList - Include/Exclude list to convert ; Return values .: Success: 1 ;                  Failure: 0 ; Author ........: SRE patterns developed from those posted by various forum members and Spiff59 in particular ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_ListToMask(ByRef $sMask, $sList)     ; Check for invalid characters within list     If StringRegExp($sList, "\\|/|:|\<|\>|\|") Then Return 0     ; Strip WS and insert | for ;     $sList = StringReplace(StringStripWS(StringRegExpReplace($sList, "\s*;\s*", ";"), 3), ";", "|")     ; Convert to SRE pattern     $sList = StringReplace(StringReplace(StringRegExpReplace($sList, "[][$^.{}()+\-]", "\\$0"), "?", "."), "*", ".*?")     ; Add prefix and suffix     $sMask =  "(?i)^(" & $sList & ")\z"     Return 1 EndFunc   ;==>_RFLTA_ListToMask ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_AddToList ; Description ...: Add element to [?] or [?][2] list which is resized if necessary ; Syntax ........: _RFLTA_AddToList(ByRef $asList, $vValue_0, [$vValue_1]) ; Parameters ....: $aList - List to be added to ;                  $vValue_0 - Value to add (to [0] element in [?][2] array if $vValue_1 exists) ;                  $vValue_1 - Value to add to [1] element in [?][2] array (optional) ; Return values .: None - array modified ByRef ; Author ........: Melba23 ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_AddToList(ByRef $aList, $vValue_0, $vValue_1 = -1)     If $vValue_1 = -1 Then ; [?] array         ; Increase list count         $aList[0] += 1         ; Double list size if too small (fewer ReDim needed)         If UBound($aList) <= $aList[0] Then ReDim $aList[UBound($aList) * 2]         ; Add value         $aList[$aList[0]] = $vValue_0     Else ; [?][2] array         $aList[0][0] += 1         If UBound($aList) <= $aList[0][0] Then ReDim $aList[UBound($aList) * 2][2]         $aList[$aList[0][0]][0] = $vValue_0         $aList[$aList[0][0]][1] = $vValue_1     EndIf EndFunc   ;==>_RFLTA_AddToList ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_AddFileLists ; Description ...: Add internal lists after resizing and optional sorting ; Syntax ........: _RFLTA_AddFileLists(ByRef $asTarget, $asSource_1, $asSource_2[, $iSort = 0]) ; Parameters ....: $asReturnList - Base list ;                  $asRootFileMatchList - First list to add ;                  $asFileMatchList - Second list to add ;                  $iSort - (Optional) Whether to sort lists before adding ;                  |$iSort = 0 (Default) No sort ;                  |$iSort = 1 Sort in descending alphabetical order ; Return values .: None - array modified ByRef ; Author ........: Melba23 ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_AddFileLists(ByRef $asTarget, $asSource_1, $asSource_2, $iSort = 0)     ; Correctly size root file match array     ReDim $asSource_1[$asSource_1[0] + 1]     ; Simple sort root file match array if required     If $iSort = 1 Then _RFLTA_ArraySort($asSource_1)     ; Copy root file match array     $asTarget = $asSource_1     ; Add file match count     $asTarget[0] += $asSource_2[0]     ; Correctly size file match array     ReDim $asSource_2[$asSource_2[0] + 1]     ; Simple sort file match array if required     If $iSort = 1 Then _RFLTA_ArraySort($asSource_2)     ; Add file match array     _RFLTA_ArrayConcatenate($asTarget, $asSource_2) EndFunc   ;==>_RFLTA_AddFileLists ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_FileListSearch ; Description ...: Search file array for beginning and end indices of folder associated files ; Syntax ........: _RFLTA_FileListSearch(Const ByRef $avArray, $vValue) ; Parameters ....: $avArray - Array to search ($asFileMatchList) ;                  $vValue  - Value to search for (Folder name from $asFolderMatchList) ;                  $iIndex  - Index to begin search (search down from here - and then from here to top if not found) ;                  $sSlash  - \ if folder names end in \ - else empty string ; Return values .: Success: Array holding top and bottom indices of folder associated files ;                  Failure: Returns -1 ; Author ........: Melba23 ; Modified.......: ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_FileListSearch(Const ByRef $avArray, $vValue, $iIndex, $sSlash)     Local $aRet[2]     ; Add final \ if required     If Not $sSlash Then $vValue &= "\"     ; Start by getting top match - search down from start index     For $i = $iIndex To $avArray[0]         ; SRE gives path less filename         If StringRegExpReplace($avArray[$i], "(^.*\\)(.*)", "\1") = $vValue Then ExitLoop     Next     If $i > $avArray[0] Then         ; No match found so look from start index upwards         If $iIndex = $avArray[0] Then $iIndex -= 1         For $i = $iIndex + 1 To 1 Step -1             If StringRegExpReplace($avArray[$i], "(^.*\\)(.*)", "\1") = $vValue Then ExitLoop         Next         ; If still no match - return " nothing found" for empty folder         If $i = 0 Then Return SetError(1, 0, "")         ; Set index of bottom file         $aRet[1] = $i         ; Now look for top match         For $i = $aRet[1] To 1 Step -1             If StringRegExpReplace($avArray[$i], "(^.*\\)(.*)", "\1") <> $vValue Then ExitLoop         Next         ; Set top match         $aRet[0] = $i + 1     Else         ; Set index of top associated file         $aRet[0] = $i         ; Now look for bottom match - find first file which does not match         For $i = $aRet[0] To $avArray[0]             If StringRegExpReplace($avArray[$i], "(^.*\\)(.*)", "\1") <> $vValue Then ExitLoop         Next         ; Set bottom match         $aRet[1] = $i - 1     EndIf     Return $aRet EndFunc   ;==>_RFLTA_FileListSearch ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_ArraySort ; Description ...: Wrapper for QuickSort function ; Syntax ........: _RFLTA_ArraySort(ByRef $avArray) ; Parameters ....: $avArray - Array to sort ;                  $iStart  - Index to start sort ;                  $iEnd    - Index to end sort ; Return values .: None - array modified ByRef ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Melba23 ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_ArraySort(ByRef $avArray, $iStart = 1, $iEnd = -99)     If $iEnd = -99 Then $iEnd = UBound($avArray) - 1     _RFLTA_QuickSort($avArray, $iStart, $iEnd) EndFunc   ;==>_RFLTA_ArraySort ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_QuickSort ; Description ...: Recursive array sort ; Syntax ........: _RFLTA_QuickSort(ByRef $avArray, ByRef $iStart, ByRef $iEnd) ; Parameters ....: $avArray - Array to sort in descending alphabetical order ;                  $iStart - Start index ;                  $iEnd - End index ; Return values .: None - array modified ByRef ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Melba23 ; Remarks .......: This function is used internally by _RFLTA_ArraySort ; =============================================================================================================================== Func _RFLTA_QuickSort(ByRef $avArray, ByRef $iStart, ByRef $iEnd)     Local $vTmp     If ($iEnd - $iStart) < 15 Then         Local $i, $j, $vCur         For $i = $iStart + 1 To $iEnd             $vTmp = $avArray[$i]             If IsNumber($vTmp) Then                 For $j = $i - 1 To $iStart Step -1                     $vCur = $avArray[$j]                     If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur) >= 0) Then ExitLoop                     $avArray[$j + 1] = $vCur                 Next             Else                 For $j = $i - 1 To $iStart Step -1                     If (StringCompare($vTmp, $avArray[$j]) >= 0) Then ExitLoop                     $avArray[$j + 1] = $avArray[$j]                 Next             EndIf             $avArray[$j + 1] = $vTmp         Next         Return     EndIf     Local $L = $iStart, $R = $iEnd, $vPivot = $avArray[Int(($iStart + $iEnd) / 2)], $fNum = IsNumber($vPivot)     Do         If $fNum Then             While ($avArray[$L] < $vPivot And IsNumber($avArray[$L])) Or (Not IsNumber($avArray[$L]) And StringCompare($avArray[$L], $vPivot) < 0)                 $L += 1             WEnd             While ($avArray[$R] > $vPivot And IsNumber($avArray[$R])) Or (Not IsNumber($avArray[$R]) And StringCompare($avArray[$R], $vPivot) > 0)                 $R -= 1             WEnd         Else             While (StringCompare($avArray[$L], $vPivot) < 0)                 $L += 1             WEnd             While (StringCompare($avArray[$R], $vPivot) > 0)                 $R -= 1             WEnd         EndIf         If $L <= $R Then             $vTmp = $avArray[$L]             $avArray[$L] = $avArray[$R]             $avArray[$R] = $vTmp             $L += 1             $R -= 1         EndIf     Until $L > $R     _RFLTA_QuickSort($avArray, $iStart, $R)     _RFLTA_QuickSort($avArray, $L, $iEnd) EndFunc   ;==>_RFLTA_QuickSort ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_ArrayConcatenate ; Description ...: Joins 2 arrays ; Syntax ........: _RFLTA_ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource) ; Parameters ....: $avArrayTarget - Base array ;                  $avArraySource - Array to add from element 1 onwards ; Return values .: None - array modified ByRef ; Author ........: Ultima ; Modified.......: Melba23 ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource)     Local $iUBoundTarget = UBound($avArrayTarget) - 1, $iUBoundSource = UBound($avArraySource)     ReDim $avArrayTarget[$iUBoundTarget + $iUBoundSource]     For $i = 1 To $iUBoundSource - 1         $avArrayTarget[$iUBoundTarget + $i] = $avArraySource[$i]     Next EndFunc   ;==>_RFLTA_ArrayConcatenate

And a zip file with both of the above: Attached File  RFLTA.zip   7.69K   725 downloads

Finally, I should mention that despite its name, this UDF is iterative and not recursive. If you do not understand why I felt it important to state that, I recommend the Recursion tutorial in the Wiki. :)

M23

NEW: johnmcloud has kindly produced a nice GUI which helps with the syntax of the UDF - you can find it here. :thumbsup:

Edited by Melba23, 12 March 2013 - 03:54 PM.

  • mesale0077, Xandy, Mechaflash and 1 other like this
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items






#2 AppTux

AppTux

    Adventurer

  • Active Members
  • PipPip
  • 130 posts

Posted 05 March 2011 - 03:17 PM

Whoa, a really useful script! Maybe for a explorer look-a-like with grouped extensions?
PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.

#3 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,241 posts

Posted 05 March 2011 - 03:53 PM

Well done, i impressed by the speed of that UDF!

But here is a few problems and remarks...

1. When i run this example:
#include "RecFileListToArray.au3" ; A sorted list of all files and folders in the Program files dir $aArray = _RecFileListToArray(@ProgramFilesDir, "*", 0, 1, 1, 2)


i got this error:
RecFileListToArray.au3 (494) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $avArray[$iElement] = $vValue ^ ERROR


2. StringRegExpReplace($sInitialPath, "\\", "") better replace with regular StringReplace function, i.e:
StringReplace($sInitialPath, "\", "") ... StringReplace($sCurrentPath, "\", "")


3. You can increase the speed even more, if you use this construction:
If $hSearch = -1 Then     ContinueLoop EndIf

instead of this:
If $hSearch = -1 Then ContinueLoop

Especialy in loops.
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#4 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 05 March 2011 - 04:16 PM

MrCreatoR,

Thanks for the comments. I worked very hard on the speed - you would not have been impressed by the early versions. :D

- 1. Array variable has incorrect number of subscripts or subscript dimension range exceeded. I do not get that error when I run exactly the same code as you - so I cannot help there unless I can have some more clues. :)

- 2. StringRegExpReplace vs StringReplace. Why do you suggest changing? :)

- 3. Single line If vs If...EndIf. I did some timing tests on the various forms of If compared to Switch and Select some time ago and (on my machine at least) the single line If was faster then the If...End structure - although not by a lot. :P

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#5 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,162 posts

Posted 05 March 2011 - 04:24 PM

I would even suggest to replace it with StringReplace($sInitialPath, "\", "", 0, 2).

$sInitialPath = @ScriptFullPath $timer = TimerInit() For $i = 0 To 100000     StringRegExpReplace($sInitialPath, "\\", "") Next ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() For $i = 0 To 100000     StringReplace($sInitialPath, "\", "") Next ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() For $i = 0 To 100000     StringReplace($sInitialPath, "\", "", 0, 2) Next ConsoleWrite(TimerDiff($timer) & @CRLF)


Edit: Maybe you want to check every standard function call supporting a "casesense" flag, as imho if you know the case (e.g. like "\" has no case) setting the flag to "2 = not case sensitive" is always much faster.

Edited by KaFu, 05 March 2011 - 04:28 PM.


#6 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 05 March 2011 - 04:36 PM

KaFu,

Interesting timings -
SRER      = 1310 SR        = 1248 SR flag 2 = 557

I will keep that in mind the next time I need to count character occurences in a string! :)

But as the line is used just the one time in this UDF, it would only save around 0.05 ms - I am not sure that even you would notice the difference. :)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#7 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,162 posts

Posted 05 March 2011 - 04:46 PM

I think there are more lines which could be replaced as imho they do not need to be checked for case sensitivity...
StringRegExpReplace($sInitialPath, "\\", "")
$sRetPath = StringReplace($sCurrentPath, $sInitialPath, "")
StringRegExpReplace($sCurrentPath, "\\", "")
$sList = StringReplace(StringStripWS(StringRegExpReplace($sList, "\s*;\s*", ";"), 3), ";", "|")
$sList = StringReplace(StringReplace(StringRegExpReplace($sList, "(\^|\$|\.)", "\\$1"), "?", "."), "*", ".*?") <<< double replacement possible

Maybe also
If StringInStr($avArray[$i], $vValue) > 0 Then Return $i
StringCompare() ?

And as you're defining array[0] = count, you could also drop some ubound() calls :).

Edited by KaFu, 05 March 2011 - 04:51 PM.


#8 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 05 March 2011 - 04:52 PM

KaFu,

The third one of those is probably worth doing as it is a loop - I will keep it in mind for the next update. Danke sehr. :)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#9 UEZ

UEZ

    Never say never

  • MVPs
  • 3,602 posts

Posted 05 March 2011 - 04:52 PM

...

- 1. Array variable has incorrect number of subscripts or subscript dimension range exceeded. I do not get that error when I run exactly the same code as you - so I cannot help there unless I can have some more clues. :)
...


It runs properly on my system, too! Win7 SP1 x64.

Br,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#10 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,241 posts

Posted 05 March 2011 - 10:45 PM

I do not get that error when I run exactly the same code as you - so I cannot help there unless I can have some more clues

It's probably related to mount of files in the folder (i got 16519 files in my program files folder), you should never write code in the way that will trigger this kind of errors, use something like this:

Func _RFLTA_ArrayInsert(ByRef $avArray, $iElement, $vValue = "")     Local $iUBound = UBound($avArray) + 1     ReDim $avArray[$iUBound]     For $i = $iUBound - 1 To $iElement + 1 Step -1         $avArray[$i] = $avArray[$i - 1]     Next         If $iElement >= $iUBound Then         ReDim $avArray[$iElement+1]     EndIf         $avArray[$iElement] = $vValue EndFunc

Btw, it's related to sort parameter, if it's 0 then no errors.

StringRegExpReplace vs StringReplace. Why do you suggest changing?

Why to use RegExp when it's not needed?

I did some timing tests on the various forms of If compared to Switch and Select some time ago and (on my machine at least) the single line If was faster then the If...End structure

A while ago i thought that way too, but i did some new tests and they shows other results.
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#11 guinness

guinness

    guinness

  • MVPs
  • 10,299 posts

Posted 05 March 2011 - 10:58 PM

I thought the same as Melba23 too, because I asked this question (about If Statements) a while back. It also it seems logical, less lines = more performance. But testing this I get a difference result to what I would have expected :)
Global $Variable = 1, $Timer $Timer = TimerInit() If $Variable = 1 Then $Variable = 1 ConsoleWrite(TimerDiff($Timer) & @CRLF) ; Average = 0.00830911064656123 $Timer = TimerInit() If $Variable = 1 Then     $Variable = 1 EndIf ConsoleWrite(TimerDiff($Timer) & @CRLF) ; Average = 0.00586525457404322

Note: Of course its not humanly noticeable!

Edited by guinness, 05 March 2011 - 10:59 PM.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#12 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 6,830 posts

Posted 05 March 2011 - 11:39 PM

@guiness
I modified the tests a bit, running each one 100 times and recording the results and running both test segments 100 times and comparing the results. So after running the tests 10,000 each the results are pretty consistent that the second test is a tiny bit faster. I don't think changing one for the other will affect much of anything in the long run unless you have 1000's of comparisons of this sort to run, but it's fun to find out the facts behind the conjecture.

Here's the code I used

Global $Variable = 1, $Timer Global $File = FileOpen("C:\Test.txt", 2) For $X = 1 To 100     $Timer = TimerInit()     For $I = 1 To 100         If $Variable = 1 Then $Variable = 1     Next     FileWrite($File, TimerDiff($Timer) & " -------- ")     $Timer = TimerInit()     For $I = 1 To 100         If $Variable = 1 Then             $Variable = 1         EndIf     Next     FileWriteLine($File, TimerDiff($Timer) & @CRLF) Next

And here's the results from one test run. Some of the results are very different than the rest probably due to the slow computer I'm running it on and hard drive access.

Spoiler

How to ask questions the smart way!

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.

Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.

_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.

GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.

Posted Image


#13 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 06 March 2011 - 08:52 AM

MrCreatoR,

- 1. _ArrayInsert function.

I do not think it is the number of files - I have nearly 70000 in my Programs folder and, although it takes some time, the UDF sorts them all perfectly well.

Thanks for the coding suggestion, but it is not a valid one in this case - and I do try to put errorchecking in my code when it is needed. :P

The value of $iElement passed to the function is the index of an existing array counting up from the max to 1, so it must be less that the current size of the array. And you can seee that the lines prior to the one which threw the error actually run from the new increased max to the value of $iElement. As I check in the main code to prevent -1 being passed, I am at a loss to explain to what might be happening. As it seems to be a problem unique to your machine and folder structure, would you mind running the code again with an added line at the very beginning of the function:
ConsoleWrite($iElement & @CRLF)

and seeing what value is passed when it crashes? Thanks in advance. :)

- 2. SRER vs StringReplace. Good point - when I was writing this I was deep in my continuing struggle to learn about the dratted things and therefore an SRER jumped to mind. Having seen KaFu's results above I will change my coding strategy from now on. :D

- 3. If structure differences. It seems to be very machine/code dependant. I remember going through all of my scripts checking that I had removed all the single item If..EndIf statements - looks like I might have to go back and do it again, but the other way round! ;)

; -------

guinness and BrewManNH,

Go start your own topic if you want to discuss If speeds! :)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#14 guinness

guinness

    guinness

  • MVPs
  • 10,299 posts

Posted 06 March 2011 - 09:19 AM

Go start your own topic if you want to discuss If speeds!

Sorry :) I use this UDF quite a bit :) so Thanks!

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#15 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,241 posts

Posted 06 March 2011 - 10:35 AM

would you mind running the code again with an added line at the very beginning of the function:

I added theese lines:

    ConsoleWrite("Index:" & $iElement & @LF)     ConsoleWrite("Ubound: " & UBound($avArray) & @LF)


Here is what i got:

Index: 16569 Ubound: 13205


as you can see, the index is grater than ubound.

You can reproduce the problem like this:
#include <Array.au3> #include "RecFileListToArray.au3" DirCreate("C:\Test\Folder\SubFolder") $aArray = _RecFileListToArray("C:\Test", "*", 0, 1, 1, 1) _ArrayDisplay($aArray)

Edited by MrCreatoR, 06 March 2011 - 10:43 AM.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#16 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 06 March 2011 - 11:54 AM

MrCreatoR,

Thank you so much for that - I have identified the problem. It was entirely of my own making - I was using the [0] element as a count and increased it too early. :)

I now use UBound and the problem is solved - for the test code you posted, at least. This error only seemed to occur if there were empty folders with subfolders at the end of the tree, which was not a scenario I had tested - I love how people manage to find dusty corners of the envelope to explore as soon as you release something! :P

New version coming as soon as I can post it - and I promise to change some SRERs as well to keep you and KaFu happy! :)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#17 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 06 March 2011 - 12:05 PM

New Version - 6 Mar 2011

Fixed - crash when sorting empty folders with subfolders at the end of the tree (thanks MrCreatoR)

Changed - Should be even faster with some StringReplace and If structure changes (thanks KaFu and guinness)

New UDF and zip in first post. :)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#18 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 06 March 2011 - 12:24 PM

Ooops!

If you downloaded the new version before 1220 UTC Sun 6 Mar, please do it again - the wrong file was in the zip! :)

M23

Edit: Added time stamp as the initial panic is over. :)

Edited by Melba23, 06 March 2011 - 02:34 PM.

StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#19 supersonic

supersonic

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 448 posts

Posted 07 March 2011 - 03:24 PM

Melba,

greate UDF - one of my favs! :)

You changed "Local $iLastIndex = $asReturnList[0]" (old version)
to "Local $iLastIndex = UBound($asReturnList)" (new version).

Is "$asReturnList" a one-based array, isn't it?
Shouldn't it be "Local $iLastIndex = UBound($asReturnList) - 1"?

I' am I wrong?

Greets,
-supersonic.

#20 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 07 March 2011 - 04:49 PM

supersonic,

Shouldn't it be "Local $iLastIndex = UBound($asReturnList) - 1"?

No! :P

Spoiler

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users