Jump to content
Sign in to follow this  


Recommended Posts


In the search function, which I saw on >this page has a drawback: the files are added to the list in reverse order. So I made a function that caches a search handle instead of path.

Local $FileList = ''
$timer = TimerInit()
_FileSearch(@WindowsDir, $FileList)
MsgBox(0, "Time", 'Time : ' & Round(TimerDiff($timer) / 1000, 2) & ' sec')

$file = FileOpen(@ScriptDir & '\file.txt', 2)
FileWrite($file, $FileList)

Func _FileSearch($sPath, ByRef $FileList)
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    If Not FileExists($sPath) Then Return SetError(1, 0, '')
    If StringInStr($sPath, '/') Then Return SetError(1, 0, '')
    Local $hSearch, $c = 0
    $hSearch = FileFindFirstFile($sPath & "*")
    If $hSearch = -1 Then Return SetError(3, 0, '')
    Local $aSearchList[125][2] = [[$hSearch, $sPath]], $sName
        $sPath = $aSearchList[$c][1]
        $sName = FileFindNextFile($aSearchList[$c][0])
        If @error Then
            $c -= 1
        If @extended Then
            $c += 1
            $aSearchList[$c][1] = $sPath & $sName & "\"
            $aSearchList[$c][0] = FileFindFirstFile($aSearchList[$c][1] & "*")
            $FileList &= $sPath & $sName & @CRLF
    Until $c < 0

    $FileList = StringTrimRight($FileList, 2)
    If Not $FileList Then Return SetError(3, 0, '')
EndFunc   ;==>_FileSearch
Edited by AZJIO

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.