Jump to content
Sign in to follow this  
norjms

Exit Function if no folders found?

Recommended Posts

I'm back with another issue. I have a function that looks in a folder and makes a list of the folders. The only problem is if there are no folders the program crashes with this exit code "Error: Subscript used with non-Array variable" I know there is error code for _FileListToArray. What I can't figure out is how to exit the function if I get errors instead of proceeding and crashing out.

Func GetFolders($String_SourceDirectory)
            If $String_SourceDirectory <> "default" Then
                $ArrayFolders =_FileListToArray($String_SourceDirectory, "*", 2)
                    #cs
                    If @Error=4 Then
                        MsgBox (0,"","No Files\Folders Found.")
                    ?exit the function to avoid array errors?
                    #CE



            For $Count = 1 To $ArrayFolders[0]

            If $String_TargetDirectory <> "default" Then

                    If FileExists($String_TargetDirectory & $ArrayFolders[$Count] & ".m4v") OR FileExists($String_TargetDirectory & $ArrayFolders[$Count] & ".mkv") OR FileExists($String_TargetDirectory & $ArrayFolders[$Count] & ".mp4") OR FileExists($String_TargetDirectory & $ArrayFolders[$Count] & ".avi") OR FileExists($String_TargetDirectory & $ArrayFolders[$Count] & ".ogm") Then

                    $String_Status = "Encoded"

                    Else
                    If FileExists($String_TargetDirectory &  "Preview - " & $ArrayFolders[$Count] & ".m4v") OR FileExists($String_TargetDirectory &  "Preview - " & $ArrayFolders[$Count] & ".mkv") OR FileExists($String_TargetDirectory &  "Preview - " & $ArrayFolders[$Count] & ".mp4") OR FileExists($String_TargetDirectory &  "Preview - " & $ArrayFolders[$Count] & ".avi") OR FileExists($String_TargetDirectory &  "Preview - " & $ArrayFolders[$Count] & ".ogm") Then

                    $String_Status = "Previewed"

                    Else
                    $String_Status = "Not Encoded"

                    EndIf

        EndIf

            Else

               $String_Status = ""
               $String_CropValues = ""

            EndIf

        GUICtrlCreateListViewItem($ArrayFolders[$Count] & "|" & $SelectedTransType & "|" & $String_Status, $Control_FilmList)
        Next

      EndIf

  EndFunc

Thanks for taking a look.

Share this post


Link to post
Share on other sites

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  

×
×
  • Create New...