Jump to content

Array - "Subscript used with non-Array variable"


 Share

Recommended Posts

The purpose of the script is to automate the process of writing a .bat script. It recursively writes in the lines of all the folders that exists within a certain directory to the batch file. The script keeps on erroring at lines 20 and 36 where the "for $i = 1 to $FolderList[0] begins" saying that "Subscript used with non-Array variable" while it is. While I see it as an Array variable :S any help will be great, thanks! :blink:

#include <File.au3>
#include <Array.au3>
Dim $Directory = @ScriptDir

if FileExists(@ScriptDir & "\SUpdate.bat") Then
    FileDelete(@ScriptDir & "\SUpdate.bat")
EndIf

$file = FileOpen("SUpdate.bat",1)
FileWriteLine($file,"@echo off")
FileWriteLine($file,"pause")
FileWriteLine($file,"rem --- SBOT Folders ---")


$FolderList = _FileListToArray($Directory,"",2)
if @error = 4 Then
    MsgBox(0,"Error", "No Folders were found!")
EndIf
$FolderNumber = 1
for $i = 1 to $FolderList[0]
    FileWriteLine($file,"set" & "" & $FolderNumber & "=" & $FolderList[$i])
    $FolderNumber += 1
Next
FileWriteLine($file,"") ;Extra space
FileWriteLine($file,"") ;Extra space


FileWriteLine($file,"rem --- Extract ---")
FileWriteLine($file,"cd c:\program files\7-zip")
FileWriteLine($file,"7z x -o%temp%\temp %1 -xr!Scripts -y")
FileWriteLine($file,"set extracted=%temp%\temp")
FileWriteLine($file,"rem -- Copy --")
FileWriteLine($file,"") ;Extra space
FileWriteLine($file,"") ;Extra space

$FolderNumber2 = 1
for $i = 1 to $FolderList[0]
    FileWriteLine($file,"cd" & $FolderNumber2)
    FileWriteLine($file,"Del SBot*.exe")
    FileWriteLine($file,"echo Copying New files...")
    FileWriteLine($file,"xcopy %extracted% %folder1% /V /Y /E")
    $FolderNumber2 += 1
Next

FileWriteLine($file,"rem --- Delete Temp/Left over files ---")
FileWriteLine($file,"echo deleting temp files . . .")
FileWriteLine($file,"rd /s /q %extracted%")
FileWriteLine($file,"echo deleting original zip file . . .")
FileWriteLine($file,"del %1")
FileWriteLine($file,"echo finished")

FileClose($file)
Edited by lbrtdy
Link to comment
Share on other sites

Line 15 should be:

$FolderList = _FileListToArray($Directory,"*",2)

And Line 5:

$Directory=@ScriptDir & "\"
Edited by taietel
Link to comment
Share on other sites

You should do some debugging

if @error Then
    MsgBox(0,"Error", "Error No : " & @error)
EndIf

see if its an error other than #4

Oh wow silly mistake lol. Thank you very much JohnOne everything works as a charm! (with taietel's adjustments too thx!) :blink: Edited by lbrtdy
Link to comment
Share on other sites

Ibrtdy, what JohnOne wrote was just for debugging. It gives you error=2 that doesn't solve your problem!  :blink: Run your script and see for yourself.

Make adjustments in that line I stated above, and run again.

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