Jump to content

Runing a command against an Array


norjms
 Share

Recommended Posts

Ok I'm a bit dumb for the like of me I can't get this to work.

I have a folder with around 500 avi files inside located @ScriptDir\Rip Source\ There are only avi files inside so I don't need to figure out the filetype prior to running the command

I have Handbrake in a folder @ScriptDir\Bin\HandbrakeCLI\HandbrakeCLI.exe

I want to run this command against every file inside the folder:

Handbrake.exe -i @ScriptDir\Rip Source\"thenameofthefile" -o @ScriptDir\Temp\"thenameofthefile minus the .ext avi" -L -f mp4 --strict-anamorphic -e x264 -q 20 -a 1 -E faac -6 dpl2 -R 48 -B 160 -D 0.0 --subtitle 1 --subtitle-burn=1 -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0 -v 1 <------this is all a one line command switch

Here is the code I have that I am at a loss on how to get it to work.

#Include <File.au3>
#Include <Array.au3>

$root = @ScriptDir



$NormalSwitch = -L -f mp4 --strict-anamorphic  -e x264 -q 20 -a 1 -E faac -6 dpl2 -R 48 -B 160 -D 0.0 --subtitle 1 --subtitle-burn=1 -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0 -v 1

$FileList =_FileListToArray($root & "\Rip Source","*", 1)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
_ArrayDisplay($FileList,"$FileList")

For $i=1 To $FileList[0]
    RunWait(@ScriptDir & "\Bin\HandbrakeCLI\HanBrakeCLI.exe -i " & @ScriptDir & "\Rip Source\" & $FileList[$i] & " " & "-o " & @ScriptDir & "\temp\" & $FileList[$i])
Next

Thanks for your help

Edited by norjms
Link to comment
Share on other sites

Change your script to:

#Include <File.au3>
#Include <Array.au3>

$root = @ScriptDir & "\Rip Source\"
$NormalSwitch = "-L -f mp4 --strict-anamorphic -e x264 -q 20 -a 1 -E faac -6 dpl2 -R 48 -B 160 -D 0.0 --subtitle 1 --subtitle-burn=1 -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0 -v 1"
$FileList =_FileListToArray($root, "*.*", 1)
If @error>0 Then
    MsgBox (0,"","No Files\Folders Found. Error: " & @error)
    Exit
EndIf
_ArrayDisplay($FileList,"$FileList")

For $i=1 To $FileList[0]
    RunWait(@ScriptDir & "\Bin\HandbrakeCLI\HanBrakeCLI.exe -i " & $root & $FileList[$i] & " " & '-o "' & @ScriptDir & "\temp\" & $FileList[$i] & '" ' & $NormalSwitch)
Next
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I got what I wanted to do working, but I can't seem to get the error code right.

#Include <File.au3>
#Include <Array.au3>
Global $Configure = (@ScriptDir & "\Configuration\Configure.ini")
$EncodePreset = IniRead($Configure,"Encode Preset","Key","default")
$CompletedExt = IniRead($Configure,"Encode Ext","Key","default")
$RipSource = IniRead($Configure, "DVD Rip Output Path", "Key", "default")
$TransCodePath = IniRead($Configure, "Transcode Path", "Key", "default")
$FileList =_FileListToArray($RipSource, "*.*", 1)
If @Error=1 Then
    MsgBox (0,"","There are no files in " & $RipSource & " " & "to proccess.")
    Exit
EndIf


For $i=1 To $FileList[0]
    $result = StringTrimRight($FileList[$i], 4)
    $myCommand = @ScriptDir&"\HandbrakeCLI\"&"HandBrakeCLI.exe -i " &'"'& $RipSource & "\" & $FileList[$i]&'" ' & '-o "' & $TransCodePath & "\" & $result & $CompletedExt&'" ' & "-preset " & '"' &$EncodePreset&'"'
    RunWait($myCommand)
Next

The error I get is:

Line 1091

Error: Subscript used with non-Array variable

What is the proper way to deal with this error?

Link to comment
Share on other sites

If IsArray($FileList) Then
For $i=1 To $FileList[0]
    $result = StringTrimRight($FileList[$i], 4)
    $myCommand = @ScriptDir&"\HandbrakeCLI\"&"HandBrakeCLI.exe -i " &'"'& $RipSource & "\" & $FileList[$i]&'" ' & '-o "' & $TransCodePath & "\" & $result & $CompletedExt&'" ' & "-preset " & '"' &$EncodePreset&'"'
    RunWait($myCommand)
Next
EndIf

Edit: You could also handle it in your existing code by moving the loop.

#Include <File.au3>
#Include <Array.au3>
Global $Configure = (@ScriptDir & "\Configuration\Configure.ini")
$EncodePreset = IniRead($Configure,"Encode Preset","Key","default")
$CompletedExt = IniRead($Configure,"Encode Ext","Key","default")
$RipSource = IniRead($Configure, "DVD Rip Output Path", "Key", "default")
$TransCodePath = IniRead($Configure, "Transcode Path", "Key", "default")
$FileList =_FileListToArray($RipSource, "*.*", 1)
If @Error Then
    MsgBox (0,"","There are no files in " & $RipSource & " " & "to proccess.")
    Exit
Else
For $i=1 To $FileList[0]
    $result = StringTrimRight($FileList[$i], 4)
    $myCommand = @ScriptDir&"\HandbrakeCLI\"&"HandBrakeCLI.exe -i " &'"'& $RipSource & "\" & $FileList[$i]&'" ' & '-o "' & $TransCodePath & "\" & $result & $CompletedExt&'" ' & "-preset " & '"' &$EncodePreset&'"'
    RunWait($myCommand)
Next
EndIf
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

@norjms: There is no array returned from _FileListToArray() if there is an error. You are only testing for @error = 1. What about @error = 4? A better test for failure would be:

If @error Then
    MsgBox (16, "Error", "Error listing files or no matching files in " & $RipSource)
    Exit
EndIf

:)

Edit: Posted before seeing GEOSoft's reply.

Edited by PsaltyDS
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
Link to comment
Share on other sites

There is no array returned from _FileListToArray() if there is an error. You are only testing for @error = 1. What about @error = 4? A better test for failure would be:

If @error Then
    MsgBox (16, "Error", "Error listing files or no matching files in " & $RipSource)
    Exit
EndIf

:)

Damn but you're fast today. I was just coming back to change that in my last bit of code.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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