Jump to content

_FileListToArray new proposal; comments?


randallc
 Share

Recommended Posts

I read WeaponX's thread that described the different techniques and showed benchmarking results. It was very informative reading. As to the exisitng FLTA: I know that caching, drive types, amount of memory will all have an effect, but splitting the code into 3 separate While loops like below, does show a noticable speed improvement. It's about 13% for me, regardless of directory size.

Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $asFileList[1]
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegexp($sFilter, "[\\/:<>|]") Or (Not StringStripWS($sFilter, 8)) Then Return SetError(2, 2, "")
    If (StringMid($sPath, StringLen($sPath), 1) = "\") Then $sPath = StringTrimRight($sPath, 1); needed for Win98 for x:\  root dir
    $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch = -1 Then Return SetError(4, 4, "")
    Switch $iFlag
        Case 0; Files and Folders
            While 1
                $sFile = FileFindNextFile($hSearch)
                If @error Then
                    SetError(0)
                    ExitLoop
                EndIf
                $asFileList[0] += 1
                If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2]
                $asFileList[$asFileList[0]] = $sFile
            WEnd
        Case 1; Files Only
            While 1
                $sFile = FileFindNextFile($hSearch)
                If @error Then
                    SetError(0)
                    ExitLoop
                EndIf
                If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") Then ContinueLoop
                $asFileList[0] += 1
                If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2]
                $asFileList[$asFileList[0]] = $sFile
            WEnd
        Case 2; Folders Only
            While 1
                $sFile = FileFindNextFile($hSearch)
                If @error Then
                    SetError(0)
                    ExitLoop
                EndIf
                If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
                $asFileList[0] += 1
                If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2]
                $asFileList[$asFileList[0]] = $sFile
            WEnd
        Case Else
            Return SetError(3, 3, "")
    EndSwitch
    FileClose($hSearch)
    ReDim $asFileList[$asFileList[0] + 1]; Trim unused slots
    Return $asFileList
EndFunc;==>_FileListToArray

Edit: switched codebox back to code to recover formatting

Edited by Spiff59
Link to comment
Share on other sites

  • 8 months later...
  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi Guys,

I'm using this function like so

$driverpath = _FileListToArray3($path, "*.inf", 2, 1, 1, "", 1)

What I'm hoping this should do is output an array of folders which contain .inf files. So far though its putting out nothing.

Am I using it wrong? Is this not what the filter is intended for?

Any help would be great thanks

Link to comment
Share on other sites

That function only uses 3 parameters.

It runs in my mind that it was re-written at one point with other parameters and I also think it was included that way in the AutoIt distro. I'm not quite sure why it's back in its original form because it seriously needs a re-write.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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