Jump to content

Recursive(iterative) FileListToArray function comparaison and comments.


tip
 Share

Recommended Posts

  • Moderators

Hi,

As the main author (but see credits in the header) of one of the UDFs under review, I have been watching this thread with interest. I feel I must interject at this point to point out that, as happened in the first post, care must be taken when using similar parameters and code structure for the different UDFs as this can give rise to misleading results. ;)

Tlem is quite correct that _RecFileListToArray returns all folders and only matching files when used with the syntax he used in his test script. However, this is exactly what the UDF is designed to do when asked to recursively return "folders and files" as is shown in the logic chart I posted in the UDF thread:

$iReturn Mode            $sInclude_List         $sExclude_List         $sExclude_List_Folder         Comment
                           applies to             applies to             applies to

$iRecur = 0                                                                                          Non-recursive search acts as _FileListToArray

0 (Files + Folders)      Files + Folders        Files + Folders        Ignored

1 (Files only)           Files only             Files only             Ignored                       

2 (Folders only)         Folders only           Folders only           Ignored                       

$iRecur <> 0

0 (Files + Folders)      Files only             Files only             Folders only                  Searches and returns all folders unless explicitly excluded

1 (Files only)           Files only             Files only             Ignored                       All folders searched

2 (Folders only)         Folders only           Folders only           Ignored

If you want to match files and folders you have to call the function twice - once for files and once for folders:

#include <RecFileListToArray.au3>

If Not FileExists("M:MyTestMyTest.txt") Then
    DirCreate("M:MyTest")
    FileWrite("M:MyTestMyTest.txt", "My Test File")
EndIf

$Path = "M:"
$Filter = "MyTest*"

$Begin = TimerInit()
$aArray1 = _RecFileListToArray($Path, $Filter, 1, 1) ; Look for matching files
$Begin = TimerInit()
$aArray2 = _RecFileListToArray($Path, $Filter, 2, 1) ; Look for matching folders
ConsoleWrite("_RecFileListToArray returned " & $aArray1[0] + $aArray2[0] & " items in " & TimerDiff($Begin) / 1000 & " seconds " & @CRLF)

DirRemove("M:MyTest", 1)

As to why you need to do this, I made quite clear in the UDF thread that:

"I wrote this UDF to meet my particular needs. As such it does exactly what I want - particularly in the sorting routine. I am well aware that there are faster ways to recursively list files but so far I have not found one which does precisely what I require- so I wrote my own UDF."

The UDF returns all the folders when asked to return "folders and files" so that when the returned array is sorted (again according to my requirements and not just a simple "one line of code" alphabetical sort) my ChooseFileFolder UDF has the full tree available - remember I wrote the UDF to do what I wanted it to do. If others also find it useful then all well and good, but its primary purpose is to be used in my scripts. Sorry if that sounds selfish - but that is the way it is.

As to the size argument, given the size of any compiled AutoIt script I have no problem with the size of any UDF as the increase in the final size of the exe will be barely noticable. Nor, within reason, do I have a problem with speed given AutoIt's less than stellar overall performance. Turning to clarity of code, I do not believe that size and complexity, nor the use of helper functions (sometimes imposed by AutoIt's limitations), necessarily imply a poor code structure. What is important is that the code should be maintainable and offer (reasonably) easy options to amend/upgrade the code if required - that should not be sacrificed to gain speed and/or to reduce the line count. If you have not read the "speed is the root of all evil" thread yet, I recommend it. ;)

To end, I personally think it is an excellent thing to have so many recursive search UDFs to choose from depending on the situation. I certainly make no claim that mine is the best in all cases. :)

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

  • 6 months later...

I used another method that was faster.

#include <String.au3>
#include <Array.au3>
global $listing = 0
Func list($path = "", $counter = 0)
$counter = 0
$path &= '\'
Local $list_files = '', $file, $demand_file = FileFindFirstFile($path & '*')
If $demand_file = -1 Then Return ''
While 1
  $file = FileFindNextFile($demand_file)
  If @error Then ExitLoop
  If @extended Then
   If $counter >= 10 Then ContinueLoop
   $listing &= $path & $file & "|"
   list($path & $file, $counter + 1)
  Else
            $listing &= $path & $file & "|"
  EndIf
WEnd
Return $listing
FileClose($demand_file)
EndFunc

-> -> List_files returned 42264 items in 0.42 seconds.

-> FileListToArrayRecursive returned 42264 items in 0.92 seconds.

-> FileListToArray3 returned 42264 items in 1.84 seconds.

-> RecFileListToArray returned 42264 items in 1.81 seconds.

-> FileListToArrayEx returned 42264 items in 0.88 seconds.

-> FileListToArrayPlus returned 42264 items in 0.75 seconds.

-> FileListTreeToArray returned 42264 items in 2.66 seconds.

Speed Test.rar

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...