Jump to content

Recommended Posts

  • Moderators
Posted

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:

  Reveal hidden contents

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:

  Reveal hidden contents

 

Posted

  On 2/9/2012 at 1:24 PM, 'Melba23 said:

Tlem is quite correct that _RecFileListToArray returns all folders and only matching files when used with the syntax he used in his test script.

Yes, but I didn't say only that !

^^

Best Regards.Thierry

  • 6 months later...
Posted

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

  Quote

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

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
  • Recently Browsing   0 members

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