Jump to content

Array won't become Array


Recommended Posts

Hi everyone.

Hope some of you knows the answer to this problem.

With this code I just get the following message:

E:\AutoIT\Episode Cleaner\CheckNGetSubs.au3 (50) : ==> Variable must be of type "Object".:
For $subfile In $ArrayY
For $subfile In $ArrayY^ ERROR
->18:33:44 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 3.252

My script goes like this:

#Include <Array.au3>
#Include "FileFindEx.au3"
$Path = "E:\sharemap\Video\TV-Series\"
Global $MAX = 8
Global $Percent = 0
Global $episodes[$MAX]

$episodes[0] = $Path & "Chuck"
$episodes[1] = $Path & "White Collar"
$episodes[2] = $Path & "House MD"
$episodes[3] = $Path & "How I Met Your Mother"
$episodes[4] = $Path & "Gossip Girl"
$episodes[5] = $Path & "Two And a Half Men"
$episodes[6] = $Path & "Heroes"
$episodes[7] = $Path & "Prison Break"

ProgressOn("Scanning", "Scanning " & $Path, "", Default, Default, 18)

For $series In $episodes
    $Display = StringTrimLeft($series, StringLen($Path))
    ProgressSet($Percent, "Scanning: " & $Display)

    $ArrayAVI = _FileListToArrayEx($series, "*.avi")
    $Temp = $ArrayAVI[0]
    _ArrayTrim($ArrayAVI, 4, 1)
    $ArrayAVI[0] = $Temp

    $ArraySRT = _FileListToArrayEx($series, "*.srt")
    $Temp = $ArraySRT[0]
    _ArrayTrim($ArraySRT, 4, 1)
    $ArraySRT[0] = $Temp

    If Not IsDeclared("ArrayX") Then
        $ArrayX = $ArrayAVI
    Else
        $ArrayX = _ArrayAdd($ArrayX, $ArrayAVI)
    EndIf

    If Not IsDeclared("ArrayY") Then
        $ArrayY = $ArraySRT
    Else
        $ArrayY = _ArrayAdd($ArrayY, $ArraySRT)
    EndIf

Next

ProgressSet(50)

For $subfile In $ArrayY
    $Display = "Cross-checking subfiles"
    ProgressSet($Percent, "Checking..", $Display)

    $Search = _ArraySearch($ArrayX, $subfile)
    If $Search > 0 Then
        _ArrayDelete($ArrayX, $Search)
        $ArrayX[0] -= 1
    EndIf
Next

ProgressSet(100)
Sleep(500)
ProgressOff()

_ArrayDisplay($ArrayX, "Missing Subtitles")

And the #Include file goes like this:

;===============================================================================
;
; Description:    lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax:          _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '')
; Parameter(s):     $sPath = Path to generate filelist for
;                   $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches
;                           Example *.exe; *.txt will find all .exe and .txt files
;                  $iFlag = determines weather to return file or folders or both.
;                   $sExclude = exclude a file from the list by all or part of its name
;                           Example: Unins* will remove all files/folders that start with Unins
;                       $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 the an empty string "" if no files are found and sets @Error on errors
;                       @Error or @extended = 1 Path not found or invalid
;                       @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude
;                      @Error or @extended = 3 Invalid $iFlag
;                       @Error or @extended = 4 No File(s) Found
;
; Author(s):        SmOke_N
; 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
;
;                   All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example
;                   The Reserved file is then read into an array, then deleted
;===============================================================================

#include-once

Func _FileListToArrayEx($s_path, $s_mask = "*.*", $i_flag = 0, $s_exclude = -1, $f_recurse = True, $f_full_path = True)

    If FileExists($s_path) = 0 Then Return SetError(1, 1, 0)

    ; Strip trailing backslash, and add one after to make sure there's only one
    $s_path = StringRegExpReplace($s_path, "[\\/]+\z", "") & "\"

    ; Set all defaults
    If $s_mask = -1 Or $s_mask = Default Then $s_mask = "*.*"
    If $i_flag = -1 Or $i_flag = Default Then $i_flag = 0
    If $s_exclude = -1 Or $s_exclude = Default Then $s_exclude = ""

    ; Look for bad chars
    If StringRegExp($s_mask, "[/:><\|]") Or StringRegExp($s_exclude, "[/:><\|]") Then
        Return SetError(2, 2, 0)
    EndIf

    ; Strip leading spaces between semi colon delimiter
    $s_mask = StringRegExpReplace($s_mask, "\s*;\s*", ";")
    If $s_exclude Then $s_exclude = StringRegExpReplace($s_exclude, "\s*;\s*", ";")

    ; Confirm mask has something in it
    If StringStripWS($s_mask, 8) = "" Then Return SetError(2, 2, 0)
    If $i_flag < 0 Or $i_flag > 2 Then Return SetError(3, 3, 0)

    ; Validate and create path + mask params
    Local $a_split = StringSplit($s_mask, ";"), $s_hold_split = ""
    For $i = 1 To $a_split[0]
        If StringStripWS($a_split[$i], 8) = "" Then ContinueLoop
        If StringRegExp($a_split[$i], "^\..*?\..*?\z") Then
            $a_split[$i] &= "*" & $a_split[$i]
        EndIf
        $s_hold_split &= '"' & $s_path & $a_split[$i] & '" '
    Next
    $s_hold_split = StringTrimRight($s_hold_split, 1)
    If $s_hold_split = "" Then $s_hold_split = '"' & $s_path & '*.*"'

    Local $i_pid, $s_stdout, $s_hold_out, $s_dir_file_only = "", $s_recurse = "/s "
    If $i_flag = 1 Then $s_dir_file_only = ":-d"
    If $i_flag = 2 Then $s_dir_file_only = ":D"
    If Not $f_recurse Then $s_recurse = ""

    $i_pid = Run(@ComSpec & " /c dir /b " & $s_recurse & "/a" & $s_dir_file_only & " " & $s_hold_split, "", @SW_HIDE, 4 + 2)

    While 1
        $s_stdout = StdoutRead($i_pid)
        If @error Then ExitLoop
        $s_hold_out &= $s_stdout
    WEnd

    $s_hold_out = StringRegExpReplace($s_hold_out, "\v+\z", "")
    If Not $s_hold_out Then Return SetError(4, 4, 0)

    ; Parse data and find matches based on flags
    Local $a_fsplit = StringSplit(StringStripCR($s_hold_out), @LF), $s_hold_ret
    $s_hold_out = ""

    If $s_exclude Then $s_exclude = StringReplace(StringReplace($s_exclude, "*", ".*?"), ";", "|")

    For $i = 1 To $a_fsplit[0]
        If $s_exclude And StringRegExp(StringRegExpReplace( _
            $a_fsplit[$i], "(.*?[\\/]+)*(.*?\z)", "\2"), "(?i)\Q" & $s_exclude & "\E") Then ContinueLoop
        If StringRegExp($a_fsplit[$i], "^\w:[\\/]+") = 0 Then $a_fsplit[$i] = $s_path & $a_fsplit[$i]
        If $f_full_path Then
            $s_hold_ret &= $a_fsplit[$i] & Chr(1)
        Else
            $s_hold_ret &= StringRegExpReplace($a_fsplit[$i], "((?:.*?[\\/]+)*)(.*?\z)", "$2") & Chr(1)
        EndIf
    Next

    $s_hold_ret = StringTrimRight($s_hold_ret, 1)
    If $s_hold_ret = "" Then Return SetError(5, 5, 0)

    Return StringSplit($s_hold_ret, Chr(1))
EndFunc

Anyone got any help? I know the $ArrayAVI and $ArraySRT works..

Please! :mellow:

Link to comment
Share on other sites

Read again the description of _ArrayAdd() and you're close to the Haha effect.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Read again the description of _ArrayAdd() and you're close to the Haha effect.

I think I'm having the same problem... after using _ArrayDelete() to delete the last element, the variable is no longer an array, it's an empty string, and so the next_ArrayInsert() will fail. I think I'll write my own __ArrayInsert() wrapper that checks for the variable being an empty string and handles it.

*Update*:

Func MyArrayAdd(ByRef $avArray, $vValue)
    If $avArray = "" Then
        $avArray = _ArrayCreate($vValue)
    Else
        _ArrayAdd( $avArray, $vValue )
    EndIf
EndFunc

Oops, I just noticed that I'm using an undocumented function _ArrayCreate which I saw in the Array.au3 include file. How naughty is that?

Edited by PhilHibbs
Link to comment
Share on other sites

That's not the same issue. The OP used _ArrayAdd wrongly (the array is passed by value and _ArrayAdd returns the index of last item)

I'd suggest:

Func MyArrayAdd(ByRef $avArray, $vValue)
 If IsArray($avArray) Then
 Return(_ArrayAdd( $avArray, $vValue))
 Else
 Dim $avArray[1] = [$vValue]
    Return 1
 EndIf
EndFunc

About _ArrayDelete, since there is no such thing as empty arrays in AutoIt, what would you return instead of an empty variable (= '') after deleting the last item?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

About _ArrayDelete, since there is no such thing as empty arrays in AutoIt, what would you return instead of an empty variable (= '') after deleting the last item?

There isn't really anything else it could do, so I can't criticize the behaviour of _ArrayDelete, it's the behaviour of _ArrayAdd that I have a problem with. Maybe it could return a "magic" string, e.g. "__EMPTYARRAY__" which _ArrayAdd could detect and handle the same way my version does. UBound already returns zero if it is supplied with a string variable, so that's compatible. The only thing that I can think of that doesn't work is ReDim, so maybe an _ArrayReDim function would also be needed to deal with this case.
Link to comment
Share on other sites

As far as I can see there is no need for a magic value, the hardened version of MyArrayAdd handles every case and is fully compatible with both standard old _ArrayAdd and _ArrayDelete as we use it.

I think it could be a valuable change to the standard _ArrayAdd. Do you whish to post a ticket yourself to propose the change?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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