Jump to content

_filelisttoarray Should Set @error To 1 If No Files/folders Found.


Recommended Posts

in the File.au3 I found under function _FileListToArray() :

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

But in the beta help:

Return Value

@Error: 1 = No files\folders found in dir 
 2 = Path Not Found. 
 3 = $iFlag was invalid.

Shouldn't "SetError(0)" be changed to "SetError(1)"?

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

  • Developers

in the File.au3 I found under function _FileListToArray() :

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

But in the beta help:

Return Value

@Error: 1 = No files\folders found in dir 
 2 = Path Not Found. 
 3 = $iFlag was invalid.

Shouldn't "SetError(0)" be changed to "SetError(1)"?

Think it sould say:

; @Error=1 Path not found or invalid

; @Error=2 Invalid $sFilter

; @Error=3 Invalid $iFlag

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

Looked again an seems like there is duplicated cases where @error is set to 0

1- No files found @error = 0

2- Success @error = 0

However if you switch number (1) to @error=1 then the return will be 1 then:

1-No files found @error = 1

2-Path not Valid @error = 1

and here you go......

.........Uh :)

Here is the function:

;===================================================
;
; Description:    lists all files and folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax:          _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
; Parameter(s):     $sPath = Path to generate filelist for
;                  $iFlag = determines weather to return file or folders or both
;                   $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details
;                       $iFlag=0(Default) Return both files and folders
;                      $iFlag=1 Return files Only
;                       $iFlag=2 Return Folders Only
;
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array containing the list of files and folders in the specified path
;                   On Failure - Returns an empty string "" if no files are found and sets @Error on errors
;                       @Error=1 Path not found or invalid
;                       @Error=2 Invalid $sFilter
;                      @Error=3 Invalid $iFlag
;
; Author(s):        SolidSnake <MetalGearX91 at Hotmail dot com>
; Note(s):          The array returned is one-dimensional and is made up as follows:
;                   $array[0] = Number of Files\Folders returned
;                   $array[1] = 1st File\Folder
;                   $array[2] = 2nd File\Folder
;                   $array[3] = 3rd File\Folder
;                   $array[n] = nth File\Folder
;
;                   Special Thanks to Helge and Layer for help with the $iFlag update
;===============================================================================
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 0
    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 0
    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
        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;==>_FileListToArray
Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

  • Developers

Looked again an seems like there is duplicated cases where @error is set to 0

1- No files found @error = 0

2- Success @error = 0

However if you switch number (1) to @error=1 then the return will be 1 then:

1-No files found @error = 1

2-Path not Valid @error = 1

and more......

.........Uh :)

No idea what you are trying to tell me here.

To me its like defined in the UDF:

; @Error=1 Path not found or invalid

; @Error=2 Invalid $sFilter

; @Error=3 Invalid $iFlag

And the UDF will return 0/@error 0 when no file is selected by the FileFilter.

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

No idea what you are trying to tell me here.

To me its like defined in the UDF:

; @Error=1 Path not found or invalid

; @Error=2 Invalid $sFilter

; @Error=3 Invalid $iFlag

And the UDF will return 0/@error 0 when no file is selected by the FileFilter.

lol ... Sorry

ok.

This function will set @error to 0 when there are no files found or the Function was successfull.

make sence?

Edit: Isn't that a problem?

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

  • Developers

lol ... Sorry

ok.

This function will set @error to 0 when there are no files found or the Function was successfull.

make sence?

Edit: Isn't that a problem?

Don't know if not finding a file is an error or not.

The other Errors are true errors ....

Don't think we should make changes unless it is broke because we might brake scripts using this function...

Edited by JdeB

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

Don't know if not finding a file is an error or not.

The other Errors are true errors ....

Don't think we should make changes unless it is broke because we might brake scripts using this function...

How about you set Error to some thing new like 6 or 4 this way no one will have problems.(maybe)

Edit: You will have to change it anyway because thsi function sets @error to 1 when the dir is invalid but the help file say it should be 2.

I don't think anyone used it yet......

It's also called BETA

anyway thanks.

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

How about you set Error to some thing new like 6 or 4 this way no one will have problems.(maybe)

Edit: You will have to change it anyway because thsi function sets @error to 1 when the dir is invalid but the help file say it should be 2.

I don't think anyone used it yet......

It's also called BETA

anyway thanks.

:)

i know this isn't constructive, i just wanted to say i'm anxiously waiting on responses to those lines... wonder if Valik is on...

***edit*** too much energy drink today, fingers moving faster than brain...

Edited by cameronsdad
Link to comment
Share on other sites

  • Developers

How about you set Error to some thing new like 6 or 4 this way no one will have problems.(maybe)

Edit: You will have to change it anyway because thsi function sets @error to 1 when the dir is invalid but the help file say it should be 2.

I don't think anyone used it yet......

It's also called BETA

anyway thanks.

Well I was thinking changing the Helpfile and update it with the correct info... not the UDF ...

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

Well I was thinking changing the Helpfile and update it with the correct info... not the UDF ...

The only way to know that no files where found is by running the IsArray() check on the return value.(I think)

You might want to put this as a note in the help file. :)

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

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