Jump to content

_FileListToArray()


/dev/null
 Share

Recommended Posts

Hi JP / SolidSnake,

there are two issues with _FileListToArray().

1.) help file: _FileListToArray() has three parameters instead of two (as documented in the help file.)

func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0).

2.) Code: There is a minor problem in the code.

If there are no files found, the error code should NOT be 0. I would suggest to set @error = 4.

$hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch=-1 then 
        SetError(0)
        Return 0
    EndIf

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • Developers

1.) help file: _FileListToArray() has three parameters instead of two (as documented in the help file.)

func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0).

<{POST_SNAPBACK}>

Already fixed for the next release (See this bug report)

2.) Code: There is a minor problem in the code.

If there are no files found, the error code should NOT be 0. I would suggest to set @error = 4.

$hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch=-1 then 
        SetError(0)
        Return 0
    EndIf

Cheers

Kurt

<{POST_SNAPBACK}>

;) Not sure if it is an real error when no file is found that qualifies the filter.....

It just returns that it found 0 files in this case.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Already fixed for the next release

Ah, O.K. I did not see that one.

;) Not sure if it is an real error when no file is found that qualifies the filter.....

It just returns that it found 0 files in this case.

Hmm, good point. However, with the same value for @error at two locations, it's hard to distinguish between those two, especially when the return value is different.

If $hSearch=-1 then 
        SetError(0)
        Return 0
    EndIf

FileClose($hSearch)
    SetError(0)
    If $asFileList[0] = 0 Then Return ""

Now, if @error == 1 I have to check if IsArray($whatever) to figure out if the function returned are some files. With distinct values for @error I better check for success or failure of the function.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Thanks /dev/null for finding the bugs and jpm for fixing my them.

about the return of 0 , Just fixed it. here is the updated code.

Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $asFileList[1]
    If Not FileExists($sPath) Then
        SetError(1)
        Return ""
    EndIf
    If (StringInStr($sFilter, "\")) or (StringInStr($sFilter, "/")) or (StringInStr($sFilter, ":")) or (StringInStr($sFilter, ">")) or (StringInStr($sFilter, "<")) or (StringInStr($sFilter, "|")) or (StringStripWS($sFilter, 8)="") Then
        SetError(2)
        Return ""
    EndIf
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then
        SetError(3)
        Return ""
    EndIf
    $asFileList[0] = 0
    $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch=-1 then 
        SetError(0)
        Return ""
    EndIf
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If $iFlag = 1 Then
            If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
        EndIf
        If $iFlag = 2 Then
            If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
        EndIf
        If $sFile = "." Or $sFile = ".." Then ContinueLoop
        ReDim $asFileList[UBound($asFileList) + 1]
        $asFileList[0] = $asFileList[0] + 1
        $asFileList[UBound($asFileList) - 1] = $sFile
    WEnd
    FileClose($hSearch)
    SetError(0)
    If $asFileList[0] = 0 Then Return ""
    Return $asFileList
EndFunc  ;==>_FileList2Array
Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Thanks /dev/null for finding the bugs and jpm for fixing my them.

about the return of 0 , Just fixed it. here is the updated code.

Thanks for the change, but you still set @error = 0 when the function does NOT find any file

If $hSearch=-1 then
        SetError(0)
        Return ""
    EndIf

AND when it finds some files.

SetError(0)
    If $asFileList[0] = 0 Then Return "" ; assume this condition does not match
    Return $asFileList

I think this should be changed, however without breaking old scripts (how ??).

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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