Sign in to follow this  
Followers 0
Wingens

Checking folder for files if empty then crash

6 posts in this topic

Hi,

i have problem, i started using an array for checking files in a folder and adding them to a combobox.

But if the folder is empty then my script crashes, i tried to check the array with:

$NAME   = GUICtrlRead($AFDELINGLIST)
                    $VAR    = IniRead("P:\Afdelingen\afdelingen.ini", "names", $NAME, "")
                GUICtrlSetState($SOFTWARE, $GUI_ENABLE)
                GUICtrlSetData($SOFTWARE, "")
                GUICtrlSetData($SOFTWARE, "Geen installatie bestanden")
                GUICtrlSetData($SOFTWARE, "================================================")
                    Local $FileList = _FileListToArray("P:\Software\Afdelingen\" & $VAR & "\", "*.*", $FLTA_FILES)
                        For $i = 1 To $FileList[0]
                            If $i <> "" Then
                                GUICtrlSetData($SOFTWARE, $FileList[$i])
                            EndIf
                        Next

But when i run my script and i get to the point where it reads the ini file (checked the values comming from that with msgbox, they are good), after that it should go to the array but then it crashes if the folder is empty, if i add a file the array works. 

How can i catch this error?

Share this post


Link to post
Share on other sites



Click _FileListToArray in the code box and read. Especially about failure and @error in the "Return Value"-section.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

 

Try this:

This "If $i <> "" Then" is useless because you start with $i with value 1 (That for). So that check is useless because it always happen this way!

Local $FileList = _FileListToArray("P:\Software\Afdelingen\" & $VAR & "\", "*.*", $FLTA_FILES)
If ($FileList[0] <> 0) Then
   For $i = 1 To $FileList[0]
        GUICtrlSetData($SOFTWARE, $FileList[$i])

   Next
EndIf

Read this too:

https://www.autoitscript.com/autoit3/docs/libfunctions/_FileListToArray.htm

Edited by DocTorCoder

DocTorCoder

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

damn, i was thinking to difficult. thanks!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

DocTorCoder, What do you think happens if the folder is empty and $FileList is not an array?

Nothing,Filelist will be empty,so size "0" and will not enter in for. I am missing something?

Or maybe will return "4 - No File(s) Found" ? Didnt test it . I just think of what would happened!

Edited by DocTorCoder

DocTorCoder

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