Sign in to follow this  
Followers 0
sonicxtacy02

Quick and probably dumb question about _filelisttoarray

5 posts in this topic

i cant seem to understand why _filelisttoarray is creating an array successfully in my script yet i cant access one of the arrays elements. The below script errors out with "Subscript used with non-array variable". However if i skip trying to define $trackfilename the script writes from the array as intended. Any help?

if fileexists($folder&"*.mp3") or fileexists($folder&"*.wma") or FileExists($folder&"*.flac") Then
        if fileexists($folder&"album.m3u") then filedelete($folder&"album.m3u")
        $listarray=_FileListToArray($folder,"*.mp3")
        $trackfilename=$listarray[1]
        $trackfilesplit=stringsplit($trackfilename, "-")
        $artist=$trackfilesplit[1]
        _FileWriteFromArray($folder&"album.m3u", $listarray)
    Else
        $artist="Unknown"
    EndIf

Share this post


Link to post
Share on other sites



are you sure its not stored in $listarray[0] instead of $listarray[1] ???

Share this post


Link to post
Share on other sites

i cant seem to understand why _filelisttoarray is creating an array successfully in my script yet i cant access one of the arrays elements. The below script errors out with "Subscript used with non-array variable". However if i skip trying to define $trackfilename the script writes from the array as intended. Any help?

Put in some error handling:

if fileexists($folder&"*.mp3") or fileexists($folder&"*.wma") or FileExists($folder&"*.flac") Then
    if fileexists($folder&"album.m3u") then filedelete($folder&"album.m3u")
    $listarray=_FileListToArray($folder,"*.mp3")
    If @error or $listarray[0] = 0 Then 
        MsgBox(16, "Error", "Error listing files: " & $folder & "*.mp3, @error = " & @error)
    Else
        $trackfilename=$listarray[1]
        $trackfilesplit=stringsplit($trackfilename, "-")
        $artist=$trackfilesplit[1]
        _FileWriteFromArray($folder&"album.m3u", $listarray)
    EndIf
Else
    $artist="Unknown"
EndIf

That will at least give you some info on the error.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

are you sure its not stored in $listarray[0] instead of $listarray[1] ???

The [0] element is always the count in the array returned from _FileListToArray(). However, if no matching files are found, [0] = 0, and there is no [1].

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The [0] element is always the count in the array returned from _FileListToArray(). However, if no matching files are found, [0] = 0, and there is no [1].

:)

i found the issue with some suggested error checking.. the problem wasnt that the variable wasnt an array... it was in my loop the test condition failed which caused the array to not be created.. hence the reason for the subscript error. thanks for the assist guys

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