Sign in to follow this  
Followers 0
Spiff59

Recursive _FileListToArray()

21 posts in this topic

#1 ·  Posted (edited)

I thought I'd post a recursive _FileListToArray() version that's approaching it's third birthday.

It's one of the latter versions buried in Tlem's 263-post thread from June 2009:

I don't claim authorship. Tlem started the ball rolling, contributing all along the way, many other members and about every MVP, MOD and even a couple DEV's had input in that thread. The function also draws from prior recursive _FileListToArray() versions.

I do think it is still the most straight-forward version floating around, having all the most useful bells and whistles, and functions both efficiently and properly. It hasn't the "depth" or "sort" options available in the newer popular version by Melba23, but it offers a very concise single-function alternative.

After nearly 3 years, I thought that something ought to be dug out of the obscurity of that massive thread (into which a lot of effort was invested by many) and placed where it's easier to find.

This is identical to post 252 from the 2009 thread except the the function name is changed, the parameters are reordered to make it backward compatible with the production _FileListToArray, and the SRER escaping special characters, that used to have the comment " ; what other characters? ", is now complete.

#include <Array.au3>
#include <File.au3>

$timer = TimerInit()
$aArray = _FileListToArrayPlus(@WindowsDir, "s*.???.*", 1, "", "*.exe.*", 1, True)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
_ArrayDisplay($aArray, $timer)
Exit

; #FUNCTION# =====================================================================================================================
; _FileListToArrayPlus($sPath, $sInclude = "*", $iFlag = 0, $sExcludeFolder = "", $sExclude = "", $iPathType = 0, $bRecursive = False)
; Name...........: _FileListToArrayPlus
; Parameters ....: $sPath: Folder to search
;    $sInclude: String to match on (wildcards allowed, multiples delimited by ;)
;    $iFlag: Returned data type. 0 = Files and folders (default), 1 = Files only, 2 = Folders only
;    $sExcludeFolder: List of folders to exclude from search (wildcards allowed, multiples delimited by ;)
;    $sExclude: List of filenames to exclude from search (wildcards allowed, multiples delimited by ;)
;    $iPathType: Returned data format. 0 = Filename only (default), 1 = Path relative to $sPath, 2 = Full path/filename
;    $bRecursive: False = Search $sPath folder only (default), True = Search $sPath and all subfolders
; Author ........: Half the AutoIt community (Forum thread #96952)
;===================================================================================================================================
Func _FileListToArrayPlus($sPath, $sInclude = "", $iFlag = 0, $sExcludeFolder = "", $sExclude = "", $iPathType = 0, $bRecursive = False)
Local $sRet = "", $sReturnFormat = ""
$sPath = StringRegExpReplace($sPath, "[/]+z", "") & "" ; ensure single trailing slash
If Not FileExists($sPath) Then Return SetError(1, 1, "")
; Edit include files list
If $sInclude = "*" Then $sInclude = ""
If $sInclude Then
     If StringRegExp($sInclude, "[/:><|]|(?s)As*z") Then Return SetError(2, 2, "") ; invalid characters test
     $sInclude = StringRegExpReplace(StringRegExpReplace($sInclude, "(s*;s*)+", ";"), "A;|;z", "") ; Strip unwanted whitespace
     $sInclude = StringRegExpReplace($sInclude, "[][$.+^{}()]", "$0"); Ignore special characters
     $sInclude = StringReplace(StringReplace(StringReplace($sInclude, "?", "."), "*", ".*?"), ";", "$|") ; Convert ? to ., * to .*?, and ; to |
     $sInclude = "(?i)A(" & $sInclude & "$)"; case-insensitive, match from first char, terminate strings
EndIf
; Edit exclude folders list
If $sExcludeFolder Then
     $sExcludeFolder = StringRegExpReplace(StringRegExpReplace($sExcludeFolder, "(s*;s*)+", ";"), "A;|;z", "") ; Strip unwanted whitespace
     $sExcludeFolder = StringRegExpReplace($sExcludeFolder, "[][$.+^{}()]", "$0"); Ignore special characters
     $sExcludeFolder = StringReplace(StringReplace(StringReplace($sExcludeFolder, "?", "."), "*", ".*?"), ";", "$|") ; Convert ?=. *=.*? ;=|
     $sExcludeFolder = "(?i)A(?!" & $sExcludeFolder & "$)"; case-insensitive, match from first char, terminate strings
EndIf
; Edit exclude files list
If $sExclude Then
     $sExclude = StringRegExpReplace(StringRegExpReplace($sExclude, "(s*;s*)+", ";"), "A;|;z", "") ; Strip unwanted whitespace
     $sExclude = StringRegExpReplace($sExclude, "[][$.+^{}()]", "$0"); Ignore special characters
     $sExclude = StringReplace(StringReplace(StringReplace($sExclude, "?", "."), "*", ".*?"), ";", "$|") ; Convert ?=. *=.*? ;=|
     $sExclude = "(?i)A(?!" & $sExclude & "$)"; case-insensitive, match from first char, terminate strings
EndIf
;   MsgBox(1,"Masks","File include: " & $sInclude & @CRLF & "File exclude: " & $sExclude & @CRLF & "Dir exclude : " & $sExcludeFolder)

    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")

    Local $sOrigPathLen = StringLen($sPath), $aQueue[64] = [1,$sPath], $iQMax = 63 ; tuned?
    While $aQueue[0]
        $WorkFolder = $aQueue[$aQueue[0]]
        $aQueue[0] -= 1
        $search = FileFindFirstFile($WorkFolder & "*")
        If @error Then ContinueLoop
        Switch $iPathType
            Case 1 ; relative path
                $sReturnFormat = StringTrimLeft($WorkFolder, $sOrigPathLen)
            Case 2 ; full path
                $sReturnFormat = $WorkFolder
        EndSwitch
        While 1
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            If @extended Then ; Folder
                If $sExcludeFolder And Not StringRegExp($file, $sExcludeFolder) Then ContinueLoop
                If $bRecursive Then
                    If $aQueue[0] = $iQMax Then
                        $iQMax += 128 ; tuned?
                        ReDim $aQueue[$iQMax + 1]
                    EndIf
                    $aQueue[0] += 1
                    $aQueue[$aQueue[0]] = $WorkFolder & $file & ""
                EndIf
                If $iFlag = 1 Then ContinueLoop
                $sRet &= $sReturnFormat & $file & "|"
            Else ; File
                If $iFlag = 2 Then ContinueLoop
                If $sInclude And Not StringRegExp($file, $sInclude) Then ContinueLoop
                If $sExclude And Not StringRegExp($file, $sExclude) Then ContinueLoop
                $sRet &= $sReturnFormat & $file & "|"
            EndIf
        WEnd
        FileClose($search)
    WEnd
    If Not $sRet Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc

Edit: Put the mysteriously disappearing "" back in. Thanks, agerrika & AZJIO

Edit2: Correct all the missing backslashes.

Edited by Spiff59
1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

How to show all folders and subfolders listed in alphabetical order?

$aArray = _FileListToArrayPlus(@WindowsDir, "s*.???.*", 2, "", "", 1, True)
Edited by Belini

Share this post


Link to post
Share on other sites

nice function, thanks, you solve my problem..


[font=verdana,geneva,sans-serif]I will do my best in this forum [/font][font=verdana,geneva,sans-serif]my code :[/font] WindowsSwitcher3d()

Share this post


Link to post
Share on other sites

Just some words :

Can be that you should take back the same name of variable from the original function for the file(s) name ($sFilter).

And, personnaly, I think that some parameters are more important than other. I would indeed see the function as this :

_FileListToArrayPlus($sPath, $sFilter = "*", $iFlag = 0[, $bRecursive = False[, $iPathType = 0[, $sExcludeFile = ""[, $sExcludeFolder = ""]]]])

Notes and explanations :

$sExcludeFolder and $sExcludeFile are really optionnal by default. Their use are totally conditioned by a specific use. So they must be on the end of the function.

$iPathType : Should not have so many flag. Path relative and Full path should widely be enough. What the interest of only filename for a recursive search ??? What about if you have the same filename on hundred folders.

If you search on the root path, you should always have only the filename ... ^^

$bRecursive : The interest of this function is the recursive search, so this parameter should be after the last "official" parameter of the original function : $iFlag.

To be complete, you should add too in the description of the function, the error code and returns.

I prefer personally the simplicity of DXRW4E function, because it corresponds more to the basic philosophy of AutoIt (except his last modification about the last flag). but now, the file and folder exclusion is a not insignificant bit extra (for some people).

Regrettably, it is necessary to put limits, because otherwise, we meet fast with a heap of similar functions (you just have to make a search on this forum). All are quite interesting because there are specific, but by too complex for a simple use.

If Dev have to add a recurcive search function, It should be the simplest possible :

_FileListToArray($sPath[, $sFilter = "*"[, $iFlag = 0[, $iRecurse = 0]]])

The result should be Path relative, because if you want full path, you just have to add $sPath.

Now, for specific use, if you want only the filename or made file or folder exeption, a simple treatment should do the work. ;)

But, this is only my point of view. :)


Best Regards.Thierry

Share this post


Link to post
Share on other sites

Tlem

The result should be Path relative, because if you want full path, you just have to add $sPath.

uneconomical shorten the path, then again to combine. Speed will be slower. In most cases, the full path is required.

If Dev have to add a recurcive search function

It would be a good idea to have at least one search function including subdirectories. Very often asked.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hello, all.

Because this function is presented to be a recursive files/folders FileListToArray, I really think that the recuse flag should be just after the file type.

In accordance with my precedent post and for be in the same philosophy than included AutoIt functions, I have changed some vars name and finally, I have added a description like others AutoIt functions. I hope that you like it!

; #FUNCTION# ====================================================================================================================
; Name...........: _FileListToArrayPlus
; Description ...: Lists files andor folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax.........: _FileListToArrayPlus($sPath[, $sFilter = "*"[, $iFlag = 0 [, $bRecursive = False[, $sExcludeFile = ""[, $sExcludeFolder = "" [, $iPathType = 1]]]]]])
; Parameters ....: $sPath   - Path to generate filelist for.
;                 $sFilter  - Optional the filter to use, default is *. (Multiple filter groups such as "*.png;*.jpg;*.bmp") Search the Autoit3 helpfile for the word "WildCards" For details.
;                 $iFlag    - Optional: specifies whether to return files folders or both
;                   |$iFlag=0 (Default) Return both files and folders
;                   |$iFlag=1 Return files only
;                   |$iFlag=2 Return Folders only
;      $sExcludeFile   - Optional: filter for file(s) exclusion. Multiple filters must be separated by ";"
;      $sExcludeFolder - Optional: filter for folder(s) exclusion. Multiple filters must be separated by ";"
;                 $bRecursive   - Optional: Use this flag to specify if you want to search in sub-directories too.
;                   |$bRecursive=False (default) Do not search in sub-directories
;                   |$bRecursive=True Search in sub-directories
;                 $iPathType  - Optional: specifies displayed path of results
;                   |$iPathType = 0 - File/folder name only
;                   |$iPathType = 1 - Relative to initial path (Default)
;                   |$iPathType = 2 - Full path included
; Return values .: @Error
;         |1 = Path not found or invalid
;                   |2 = Invalid $sFilter
;                   |3 = Invalid $iFlag
;                   |4 = No File(s)/Folder(s) Found
; Author ........: Half the AutoIt community (Forum thread #96952)
; Modified.......:
; Remarks .......: The array returned is one-dimensional and is made up as follows:
;                              $array[0] = Number of FilesFolders returned
;                              $array[1] = 1st FileFolder
;                              $array[2] = 2nd FileFolder
;                              $array[3] = 3rd FileFolder
;                              $array[n] = nth FileFolder
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/topic/139336-recursive-filelisttoarray/
; Example .......: Yes
; Note ..........: Special Thanks to the AutoIt community
; ===============================================================================================================================
Func _FileListToArrayPlus($sPath, $sFilter = "", $iFlag = 0, $bRecursive = False, $sExcludeFolder = "", $sExcludeFile = "", $iPathType = 1)
Local $sRet = "", $sReturnFormat = ""
$sPath = StringRegExpReplace($sPath, "[/]+z", "") & "" ; ensure single trailing slash
If Not FileExists($sPath) Then Return SetError(1, 1, "")
; Edit include files list
If $sFilter = "*" Then $sFilter = ""
If $sFilter Then
  If StringRegExp($sFilter, "[/:><|]|(?s)As*z") Then Return SetError(2, 2, "") ; invalid characters test
  $sFilter = StringRegExpReplace(StringRegExpReplace($sFilter, "(s*;s*)+", ";"), "A;|;z", "") ; Strip unwanted whitespace
  $sFilter = StringRegExpReplace($sFilter, "[][$.+^{}()]", "$0"); Ignore special characters
  $sFilter = StringReplace(StringReplace(StringReplace($sFilter, "?", "."), "*", ".*?"), ";", "$|") ; Convert ? to ., * to .*?, and ; to |
  $sFilter = "(?i)A(" & $sFilter & "$)"; case-insensitive, match from first char, terminate strings
EndIf
; Edit exclude folders list
If $sExcludeFolder Then
  $sExcludeFolder = StringRegExpReplace(StringRegExpReplace($sExcludeFolder, "(s*;s*)+", ";"), "A;|;z", "") ; Strip unwanted whitespace
  $sExcludeFolder = StringRegExpReplace($sExcludeFolder, "[][$.+^{}()]", "$0"); Ignore special characters
  $sExcludeFolder = StringReplace(StringReplace(StringReplace($sExcludeFolder, "?", "."), "*", ".*?"), ";", "$|") ; Convert ?=.  *=.*?  ;=|
  $sExcludeFolder = "(?i)A(?!" & $sExcludeFolder & "$)"; case-insensitive, match from first char, terminate strings
EndIf
; Edit exclude files list
If $sExcludeFile Then
  $sExcludeFile = StringRegExpReplace(StringRegExpReplace($sExcludeFile, "(s*;s*)+", ";"), "A;|;z", "") ; Strip unwanted whitespace
  $sExcludeFile = StringRegExpReplace($sExcludeFile, "[][$.+^{}()]", "$0"); Ignore special characters
  $sExcludeFile = StringReplace(StringReplace(StringReplace($sExcludeFile, "?", "."), "*", ".*?"), ";", "$|") ; Convert ?=.  *=.*?  ;=|
  $sExcludeFile = "(?i)A(?!" & $sExcludeFile & "$)"; case-insensitive, match from first char, terminate strings
EndIf
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
Local $sOrigPathLen = StringLen($sPath), $aQueue[64] = [1, $sPath], $iQMax = 63 ; tuned?
While $aQueue[0]
  $WorkFolder = $aQueue[$aQueue[0]]
  $aQueue[0] -= 1
  $search = FileFindFirstFile($WorkFolder & "*")
  If @error Then ContinueLoop
  Switch $iPathType
   Case 1 ; relative path
    $sReturnFormat = StringTrimLeft($WorkFolder, $sOrigPathLen)
   Case 2 ; full path
    $sReturnFormat = $WorkFolder
  EndSwitch
  While 1
   $file = FileFindNextFile($search)
   If @error Then ExitLoop
   If @extended Then ; Folder
    If $sExcludeFolder And Not StringRegExp($file, $sExcludeFolder) Then ContinueLoop
    If $bRecursive Then
     If $aQueue[0] = $iQMax Then
      $iQMax += 128 ; tuned?
      ReDim $aQueue[$iQMax + 1]
     EndIf
     $aQueue[0] += 1
     $aQueue[$aQueue[0]] = $WorkFolder & $file & ""
    EndIf
    If $iFlag = 1 Then ContinueLoop
    $sRet &= $sReturnFormat & $file & "|"
   Else ; File
    If $iFlag = 2 Then ContinueLoop
    If $sFilter And Not StringRegExp($file, $sFilter) Then ContinueLoop
    If $sExcludeFile And Not StringRegExp($file, $sExcludeFile) Then ContinueLoop
    $sRet &= $sReturnFormat & $file & "|"
   EndIf
  WEnd
  FileClose($search)
WEnd
If Not $sRet Then Return SetError(4, 4, "")
Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc   ;==>_FileListToArrayPlus

It has not a lot of importance, but the way which are listed files/ folders is rather disturbing !

Edited by Tlem

Best Regards.Thierry

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hello,

Agree with the last changes made by Tlem

I found a mistake using it. Missing in the following line

$aQueue[$aQueue[0]] = $WorkFolder & $file & ""
$aQueue[$aQueue[0]] = $WorkFolder & $file & ""
Edited by agerrika

Share this post


Link to post
Share on other sites

This is a problem forum. Symbol disappears, not only in this. When the example was uploaded it was without errors.

Share this post


Link to post
Share on other sites

Just out of curiosity is this a feature request to update _FileListToArray?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_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()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

guinness,

I think AZJIO is referring to the nasty habit the forum software has of removing "" characters from uploaded code from time to time. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Ah, I meant Spiff59's post.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_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()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Just out of curiosity is this a feature request to update _FileListToArray?

That was the initial intention of the 2009 thread with 260+ posts.

We had one Dev fully in favor of the idea, but later in the thread another Dev indicated he had no interest in replacing a 27-line function with one of 64 lines (even though the additional functionality was one constantly requested). The thread did end up creating a bugtrack entry, one that reduced the production _FileListToArray() down to it's current 18 lines.

Share this post


Link to post
Share on other sites

I saw your addition/report and have to say what a clever approach, especially >> If ($iFlag + @extended = 2) Then ContinueLoop, most would have used a If..Else. Just nice!


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_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()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Just nice!

Thank you, Sir ;)

It was convenient that the required logic allowed for such trickery.

I, personally, still think a _FileListToArray() that processed subfolders would be a worthwhile addition to the production UDF. Whether this version, or this version with some changes, or a completely different version doesn't really matter (although I don't think anyone has beaten this version in a speed test to date).

The inclusion of a production _FileListToArray() with folder recursion would, in perpetuity, reduce the number of threads in the general help forum by at least a couple a month.

Share this post


Link to post
Share on other sites

Why is it not working?

Returns the folder "System32"

$aArray = _FileListToArrayPlus(@SystemDir)
When I patched the code because the forum oddly removes backslash characters, I only corrected one line and neglected to fix this one:

$sPath = StringRegExpReplace($sPath, "[/]+z", "") & "" ; ensure single trailing slash

which should be

$sPath = StringRegExpReplace($sPath, "[/]+z", "") & "" ; ensure single trailing slash

fixed now

Share this post


Link to post
Share on other sites

My only gripe is that it doesn't support the Default keyword.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_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()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

$aArray = _FileListToArrayPlus(@WindowsDir, "s*.???.*", 1, "", "*.exe.*", 1, True)
Returns 400 files. Do not match the mask. For example TASKMAN.EXE. The name must contain two dots.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

$aArray = _FileListToArrayPlus(@WindowsDir, "s*.???.*", 1, "", "*.exe.*", 1, True)
Returns 400 files. Do not match the mask. For example TASKMAN.EXE. The name must contain two dots.

Geez, I had thought the forum glitch had only converted "" into "".

It did more than that! All the backslashes are missing from the regular expressions.

I'll fix it when I get to work in the morning.

Thanks.

Edit: I replaced all the SRER statements.

Edited by Spiff59

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0