Jump to content

Question for DEV members about functions that list files to array


Tlem
 Share

Recommended Posts

Hi,

I would like to submit a dilemma about functions that list files/dirs in array.

First, this is a test code with _FileListToArray and _FileListToArrayRec functions from the last beta version :

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

; Only for AutoIt 3.3.9.x

Global $Dir1, $Dir2, $aSearch

; Create Dir structure for testing
$Dir1 = @TempDir & "\test1"
$Dir2 = @TempDir & "\test.2"
DirCreate($Dir1)
DirCreate($Dir2)

$aSearch = _FileListToArray(@TempDir, "*test*.*", 2)
_ArrayDisplay($aSearch, "_FileListToArray result")

$aSearch = _FileListToArrayRec(@TempDir, "*test*.*", 2)
_ArrayDisplay($aSearch, "_FileListToArrayRec result")

; Clean Test dir
DirRemove($Dir1)
DirRemove($Dir2)

If you run it, you can see that the result isn't the same for the same search.

If I try the same search on Windows, both directories returned well, but on Unix based OS (Linux and probably Mac OS), only one directory is returned. Yes I know that AutoIt is a Windows tool, but it can be another Windows bug !

Personally, I think that if I search "*test*.*", as the point is specified, the search should not send back the "test" Dir but can be that I am wrong. ^^

Best Regards.Thierry

Link to comment
Share on other sites

Welcome.
I have read your post and the problem seemed to me to be known.
Could you take a look at my old post, and see if in your case it is the same problem?

'?do=embed' frameborder='0' data-embedContent>>

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • Moderators

Tlem,

The 2 functions work very differently internally.

FLTA just runs FileFindFirstFile using the passed filter - when I run your script it uses the following:

C:\Users\Melba23\AppData\Local\Temp\*test*.*
and it does no tests on the returns, so the 2 folders are actually returned by Windows.

FLTAR runs FileFindFirstFile using the following:

C:\Users\Melba23\AppData\Local\Temp\*
and then uses an SRE to match against the passed filter. I imagine the 2 folders are still returned by Windows, but the UDF will only return the one that matches the filter.

So I believe that it is a Windows "feature/bug" - particularly as you say other OSes only return one of the two! :D

M23

P.S. I am moving this to Developer Chat.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

The 2 functions work very differently internally.

 

Yes, I know it (remember discussions about this with me). ;)

It's just that 2 functions in Beta version of AutoIt (and actual version with the good include) doesn't give the same result for the same search.  ^^

 

So I believe that it is a Windows "feature/bug" - particularly as you say other OSes only return one of the two! :D

 

Yes. So what can we do. Did we trust Microsoft or did we trust all others.

What is the function which returns the good result? o:)

Edited by Tlem

Best Regards.Thierry

Link to comment
Share on other sites

But if you're looking for a couple of files, the result is the same. I see no problem.

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

  • Moderators

DatMCEyeBall,

 

But if you're looking for a couple of files, the result is the same

But the script Tlem posted does look for 2 files and the result is not the same. ;)

Tlem,

The filenames you chose seem a pretty tough test for any search algorithm. There do not appear to be many complaints about searches by either of the functions when asked to work with the more likely filters used in "day to day" searches, so personally I am not really that fussed that the returns are not identical when used with "edge of the envelope" wildcards. But others might feel differently - let us see. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

In fact, this strange behavior was evoked in a subject of the French forum.

Personnaly the result from FileListToArrayRec and FileListToArrayEx satisfy me.

I opened this subject simply to evoke the difference of result between two functions which should give the same result for an identical searching. It seems to me that it should not be. But can being I made a mistake. ^^

Let's see what 'the others' might feel.

Best Regards.Thierry

Link to comment
Share on other sites

there are also a bug #2453 - FileFindNextFile can find not-matching mask files if non-English letters presented in the file name

As explained in the thread you linked in that trak ticket, that's not an AutoIt problem, it's a Windows one. Why would you post it as a bug when it's clearly not?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

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 editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

Tlem,

I have been doing some research into this. The main advantage of FLTA over FLTAR is (and always has been) speed - one of the reasons being that the FileFindFirst/NextFile loop only returns those items which match the filter rather than FLTAR's method of returning all files which are then compared to a mask by a RegEx. I have coded a modified version of FLTA which also uses a RegEx to scan all returned files and it too suffers the same slowdown:

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

; Only for AutoIt 3.3.9.x

Global $Dir1, $Dir2, $aSearch

; Create Dir structure for testing
$Dir1 = @TempDir & "\test1"
$Dir2 = @TempDir & "\test.2"
DirCreate($Dir1)
DirCreate($Dir2)

$nBegin = TimerInit()
$aSearch = _FileListToArray_Test(@TempDir, "*test*.*", 2)
ConsoleWrite("FLTA: " & TimerDiff($nBegin) & @CRLF)
_ArrayDisplay($aSearch, "_FLTA result")

$nBegin = TimerInit()
$aSearch = _FileListToArrayRec_Test(@TempDir, "*test*.*", 2)
ConsoleWrite("FLTAR: " & TimerDiff($nBegin) & @CRLF)
_ArrayDisplay($aSearch, "_FLTAR result")

$nBegin = TimerInit()
$aSearch = _FileListToArray_SRE(@TempDir, "*test*.*", 2)
ConsoleWrite("FLTA_SRE: " & TimerDiff($nBegin) & @CRLF)
_ArrayDisplay($aSearch, "_FLTA_SRE result")

; Clean Test dir
DirRemove($Dir1)
DirRemove($Dir2)

Func _FileListToArray_Test($sFilePath, $sFilter = "*", $iFlag = 0, $fReturnPath = False)
    Local $sDelimiter = "|", $sFileList = "", $sFileName = "", $sFullPath = ""

    ; Check parameters for the Default keyword or they meet a certain criteria
    $sFilePath = StringRegExpReplace($sFilePath, "[\\/]+$", "") & "\" ; Ensure a single trailing backslash
    If $iFlag = Default Then $iFlag = 0
    If $fReturnPath Then $sFullPath = $sFilePath
    If $sFilter = Default Then $sFilter = "*"

    ; Check if the directory exists
    If Not FileExists($sFilePath) Then Return SetError(1, 0, 0)
    If StringRegExp($sFilter, "[\\/:><\|]|(?s)^\s*$") Then Return SetError(2, 0, 0)
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 0, 0)
    Local $hSearch = FileFindFirstFile($sFilePath & $sFilter)
    If @error Then Return SetError(4, 0, 0)
    While 1
        $sFileName = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If ($iFlag + @extended = 2) Then ContinueLoop
        $sFileList &= $sDelimiter & $sFullPath & $sFileName
    WEnd
    FileClose($hSearch)
    If $sFileList = "" Then Return SetError(4, 0, 0)
    Return StringSplit(StringTrimLeft($sFileList, 1), $sDelimiter)
EndFunc   ;==>_FileListToArray_Test

Func _FileListToArrayRec_Test($sInitialPath, $sMask = "*", $iReturn = 0, $iRecur = 0, $iSort = 0, $iReturnPath = 1)
    Local $asReturnList[100] = [0], $asFileMatchList[100] = [0], $asRootFileMatchList[100] = [0], $asFolderMatchList[100] = [0], $asFolderSearchList[100] = [1]
    Local $sInclude_List = "*", $sExclude_List, $sExclude_List_Folder, $sInclude_File_Mask = ".+", $sExclude_File_Mask = ":", $sInclude_Folder_Mask = ".+", $sExclude_Folder_Mask = ":"
    Local $sFolderSlash = "", $iMaxLevel, $hSearch, $fFolder, $sRetPath = "", $sCurrentPath, $sName, $iAttribs, $iHide_HS = 0, $iHide_Link = 0, $fLongPath = False
    Local $asFolderFileSectionList[100][2] = [[0, 0]], $sFolderToFind, $iFileSectionStartIndex, $iFileSectionEndIndex

    ; Check for valid path
    If StringLeft($sInitialPath, 4) == "\\?\" Then
        $fLongPath = True
    EndIf
    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 Default keyword
    If $sMask = Default Then $sMask = "*"
    If $iReturn = Default Then $iReturn = 0
    If $iRecur = Default Then $iRecur = 0
    If $iSort = Default Then $iSort = 0
    If $iReturnPath = Default Then $iReturnPath = 1

    ; 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_Link = 0x400
        $iReturn -= 16
    EndIf

    ; Check for valid recur value
    If $iRecur > 1 Or Not IsInt($iRecur) Then Return SetError(1, 6, "")
    ; If required, determine \ count for max recursive level setting
    If $iRecur < 0 Then
        StringReplace($sInitialPath, "\", "", 0, $STR_NOCASESENSEBASIC)
        $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
        If Not __FLTAR_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
            EndSwitch
        Case 2
            ; Folders affected by mask
            $sInclude_Folder_Mask = $sInclude_File_Mask
    EndSwitch

    ; Create Exclude List mask for files
    If $sExclude_List <> "" Then
        If Not __FLTAR_ListToMask($sExclude_File_Mask, $sExclude_List) Then Return SetError(1, 3, "")
    EndIf

    ; Create Exclude mask for folders
    If $iRecur Then
        If $sExclude_List_Folder Then
            If Not __FLTAR_ListToMask($sExclude_Folder_Mask, $sExclude_List_Folder) Then Return SetError(1, 4, "")
        EndIf
        ; If folders only
        If $iReturn = 2 Then
            ; Folders affected by normal mask
            $sExclude_Folder_Mask = $sExclude_File_Mask
        EndIf
    Else
        ; Folders affected by normal mask
        $sExclude_Folder_Mask = $sExclude_File_Mask
    EndIf

    ; Verify other parameters
    If Not ($iReturn = 0 Or $iReturn = 1 Or $iReturn = 2) Then Return SetError(1, 5, "")
    If Not ($iSort = 0 Or $iSort = 1 Or $iSort = 2) Then Return SetError(1, 7, "")
    If Not ($iReturnPath = 0 Or $iReturnPath = 1 Or $iReturnPath = 2) Then Return SetError(1, 8, "")

    ; 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
                If $fLongPath Then
                    $sRetPath = StringTrimLeft($sCurrentPath, 4)
                Else
                    $sRetPath = $sCurrentPath
                EndIf
        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
            __FLTAR_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, $STR_NOCASESENSEBASIC)
                        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
                            __FLTAR_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
                        __FLTAR_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
                            __FLTAR_AddToList($asRootFileMatchList, $sRetPath & $sName)
                        Else
                            __FLTAR_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
                        __FLTAR_AddToList($asReturnList, $sRetPath & $sName & $sFolderSlash)
                    EndIf
                Else
                    If $iReturn <> 2 And StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then
                        __FLTAR_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

    ; Sort results if required
    If $iSort Then
        Switch $iReturn
            Case 2 ; Folders only
                ; Check if any folders found
                If $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "")
                ; Correctly size folder match list
                ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]
                ; Copy size folder match array
                $asReturnList = $asFolderMatchList
                ; Simple sort list
                __ArrayDualPivotSort($asReturnList, 1, $asReturnList[0])
            Case 1 ; Files only
                ; Check if any files found
                If $asRootFileMatchList[0] = 0 And $asFileMatchList[0] = 0 Then Return SetError(1, 9, "")
                If $iReturnPath = 0 Then ; names only so simple sort suffices
                    ; Combine file match lists
                    __FLTAR_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)
                    ; Simple sort combined file list
                    __ArrayDualPivotSort($asReturnList, 1, $asReturnList[0])
                Else
                    ; Combine sorted file match lists
                    __FLTAR_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList, 1)
                EndIf
            Case 0 ; Both files and folders
                ; Check if any root files or folders found
                If $asRootFileMatchList[0] = 0 And $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "")
                If $iReturnPath = 0 Then ; names only so simple sort suffices
                    ; Combine file match lists
                    __FLTAR_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]
                    _ArrayConcatenate($asReturnList, $asFolderMatchList)
                    ; Simple sort final list
                    __ArrayDualPivotSort($asReturnList, 1, $asReturnList[0])
                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
                    __ArrayDualPivotSort($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
                    __ArrayDualPivotSort($asFolderMatchList, 1, $asFolderMatchList[0])
                    ; Work through folder list
                    For $i = 1 To $asFolderMatchList[0]
                        ; Add folder to return list
                        $asReturnList[$iNextInsertionIndex] = $asFolderMatchList[$i]
                        $iNextInsertionIndex += 1
                        ; 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 found then deal with files
                            If $sFolderToFind = $asFolderFileSectionList[$j][0] Then
                                ; 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
                                    __ArrayDualPivotSort($asFileMatchList, $iFileSectionStartIndex, $iFileSectionEndIndex)
                                EndIf
                                ; Add files to return list
                                For $k = $iFileSectionStartIndex To $iFileSectionEndIndex
                                    $asReturnList[$iNextInsertionIndex] = $asFileMatchList[$k]
                                    $iNextInsertionIndex += 1
                                Next
                                ExitLoop
                            EndIf
                        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   ;==>_FileListToArrayRec_Test

Func _FileListToArray_SRE($sFilePath, $sFilter = "*", $iFlag = 0, $fReturnPath = False)

    Local $sDelimiter = "|", $sFileList = "", $sFileName = "", $sFullPath = ""

    ; Convert filter to SRE pattern
    If StringRegExp($sFilter, "\\|/|:|\<|\>|\|") Then Return SetError(2, 0, 0)
    Local $sSRE_Pattern = StringReplace(StringStripWS(StringRegExpReplace($sFilter, "\s*;\s*", ";"), 3), ";", "|")
    $sSRE_Pattern = StringReplace(StringReplace(StringRegExpReplace($sSRE_Pattern, "[][$^.{}()+\-]", "\\$0"), "?", "."), "*", ".*?")
    $sSRE_Pattern = "(?i)^(" & $sSRE_Pattern & ")\z"

    ; Check parameters for the Default keyword or they meet a certain criteria
    $sFilePath = StringRegExpReplace($sFilePath, "[\\/]+$", "") & "\" ; Ensure a single trailing backslash
    If $iFlag = Default Then $iFlag = 0
    If $fReturnPath Then $sFullPath = $sFilePath
    If $sFilter = Default Then $sFilter = "*"

    ; Check if the directory exists
    If Not FileExists($sFilePath) Then Return SetError(1, 0, 0)
    ;If StringRegExp($sFilter, "[\\/:><\|]|(?s)^\s*$") Then Return SetError(2, 0, 0)
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 0, 0)
    Local $hSearch = FileFindFirstFile($sFilePath & "*")
    If @error Then Return SetError(4, 0, 0)
    While 1
        $sFileName = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If ($iFlag + @extended = 2) Then ContinueLoop
        ; Check return matches pattern
        If StringRegExp($sFileName, $sSRE_Pattern) Then $sFileList &= $sDelimiter & $sFullPath & $sFileName
    WEnd
    FileClose($hSearch)
    If $sFileList = "" Then Return SetError(4, 0, 0)
    Return StringSplit(StringTrimLeft($sFileList, 1), $sDelimiter)
EndFunc   ;==>_FileListToArray_SRE
On my machine the timings are approx 1ms, 5ms, and 3ms - clearly indicating the speed advantage of using the FileFindFirst/NextFile loop to do the initial triage at a very low level rather than an SRE in AutoIt code.

Perhaps we should add a remark to FLTA mentioning that it does return some odd results if used with extreme wildcard filters but that its speed advantage when searching for less complex filenames is considered adequate compensation. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

@Melba

I have no problem with 'Speed', 'FLTA', 'FLTAR' and other function like this.

Like saying before personally, I use 'FLTAEx' and sometimes 'FLTAR' for their multiple options.

I present here only strange symptoms of two functions which are sensible to send back the same result and which do not make it.

At the same time, I point at a possible bug of Windows which could be corrected.

Now, the dilemma is to know who to believe for the logic of return (Windows or Unix). I know that it can be consider for a Troll, but the reality is here, somebody is necessarily wrong. AutoIt has necessarily no duty to respect the errors of others. Thus if an improvement can be envisaged, why go without it?

@Other (Not Dev & Mod)

This subject is intended to ask Dev members about a particular problem, not to link other trak ticket that are not really identical.

So, thank you for making your own subjects.

Best Regards.Thierry

Link to comment
Share on other sites

  • Moderators

Tlem,

 

Now, the dilemma is to know who to believe for the logic of return (Windows or Unix)

[...]

but the reality is here, somebody is necessarily wrong

I do not see this as a dilemma. If you run on Windows, as Autoit is intended to do, then you must accept that Windows gives you the "true" return - who cares what Unix or any other OS returns. If you run on another OS then their rules apply - "When in Rome....." as they say. ;)

Now you may not agree with what MS have decided is the "truth", but you cannot change it - other than by wrapping the behaviour in an Autoit function with the inevitable problems that brings. Another example that springs to mind is the fact that Ctrl-A does not work in Edit controls - you can get round this by using an Accelerator key in AutoIt, but why was it not included as standard by Windows? :huh:

 

AutoIt has necessarily no duty to respect the errors of others. Thus if an improvement can be envisaged, why go without it?

Now we are entirely in agreement. Hence my suggestion to add a remark to both FLTA and FLTAR mentioning that the return of the former when used with extreme wildcard filters might not be entirely as expected and that FLTAR might offer a more reasonable solution - albeit at some cost in script performance. We can then leave the choice of which function is more suitable to the user - simple filter in a single folder = FLTA; extreme wildcard or multiple filter, or recusive search = FLTAR. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I have neither the knowledge, nor the capacity to change anything. I just content with presenting facts which were evoked on the french forum.

As for me, I use that I have under the hand, the rest is only utopia.

I'm okay with your conclusion. Do what you think the best for the community.

Best Regards.Thierry

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...