Batch merging using bat and text variables

October 2, 2015 at 12:41:00
Specs: Windows 7
Hello!
I want to merge some audio, video and subtitle files into one. Lot of times. I wrote some code for command prompt to do it automatically but there are some mistakes which I cannot identify. I wanted to make code kind of flexible. I mean if I have another batch of files I can easily change some variables and it would work. So in the mkvmerge parameters part I replaced all params that could change to variables. All the code before this part is working correctly. Please help me to correct syntax of the mkvmerge part.

@echo off
Setlocal EnableDelayedExpansion

rem define files paths and some information about them. $ is put instead of serie number
rem output file name
set "outName=D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/Output/Kill la Kill - Episode $.mkv"
set "input1=D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/Kill la Kill - Episode $.mkv"

set "input2=D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Sound/[Gezell]/[Beatrice-Raws] Kill la Kill $ [BDRip 1920x1080 x264 FLAC].mka"
set "name2=Gezell"
set "lang2=rus"

set "input3=D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Sound/[Rise]/[Beatrice-Raws] Kill la Kill $ [BDRip 1920x1080 x264 FLAC].mka"
set "name3=Rise"
set "lang3=rus"

set "input4=D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Sound/[TrinaD ^& Cuba77]/[Beatrice-Raws] Kill la Kill $ [BDRip 1920x1080 x264 FLAC].mka"
set "name4=TrinaD ^& Cuba77"
set "lang4=rus"

set "input5=D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Sound/[Zendos ^& Eladiel]/[Beatrice-Raws] Kill la Kill $ [BDRip 1920x1080 x264 FLAC].mka"
set "name5=Zendos ^& Eladiel"
set "lang5=rus"

set "input6=D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Subs/[Beatrice-Raws] Kill la Kill $ [BDRip 1920x1080 x264 FLAC].ass"
set "name6=full"
set "lang6=rus"

set "input7=D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Subs/captions/[Beatrice-Raws] Kill la Kill $ [BDRip 1920x1080 x264 FLAC].captions.ass"
set "name7=captions"
set "lang7=rus"

rem let's start
for /l %%i in (1,1,5) do (
rem change $ to number. if it less than 10 add 0 before number
if 9 LSS %%i (
set inc=%%i
) else (
set inc=0%%i)
set outName=%outName:$=!inc!%
set input1=%input1:$=!inc!%
set input2=%input2:$=!inc!%
set input3=%input3:$=!inc!%
set input4=%input4:$=!inc!%
set input5=%input5:$=!inc!%
set input6=%input6:$=!inc!%
set input7=%input7:$=!inc!%

rem so here is the problem part
rem give all the parameters to the MKVMerge. The problem is that it does not work and I don't know why. Well I'm not sure that I handled the syntax correctly. The point is if I change all the parameters !input! %name% and %lang% to their actual value, the code will execute.
"D:/Program files\mkvtoolnix\mkvmerge.exe" ^"--output^" ^"!outName!^" ^"--language^" ^"0:jpn^" ^"--track-name^" ^"0:Default video^" ^"--default-track^" ^"0:yes^" ^"--language^" ^"1:jpn^" ^"--track-name^" ^"1:Original^" ^"--default-track^" ^"1:no^" ^"--language^" ^"2:jpn^" ^"--track-name^" ^"2:Japanese Subs^" ^"--default-track^" ^"2:no^" ( ^"!input1!^" ) ^"--language^" ^"0:%lang6%^" ^"--track-name^" ^"0:%name6%^" ^"--default-track^" ^"0:yes^" ( ^"!input6!^" ) ^"--language^" ^"0:%lang7%^" ^"--track-name^" ^"0:%name7%^" ( ^"!input7!^" ) ^"--language^" ^"0:%lang2%^" ^"--track-name^" ^"0:%name2%^" ( ^"!input2!^" ) ^"--language^" ^"0:%lang3%^" ^"--track-name^" ^"0:%name3%^" ( ^"!input3!^" ) ^"--language^" ^"0:%lang4%^" ^"--track-name^" ^"0:%name4%^" ( ^"!input4!^" ) ^"--language^" ^"0:%lang5%^" ^"--track-name^" ^"0:%name5%^" ( ^"!input5!^" ) ^"--track-order^" ^"0:0,0:1,0:2,1:0,2:0,3:0,4:0,5:0,6:0^"
)
set /p input="Press enter..."

By the last comment i meant that the following would execute (I've checked))
"D:/Program files\mkvtoolnix\mkvmerge.exe" ^"--output^" ^"D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/Output/Kill la Kill - Episode 01.mkv^" ^"--language^" ^"0:jpn^" ^"--track-name^" ^"0:Default video^" ^"--default-track^" ^"0:yes^" ^"--language^" ^"1:jpn^" ^"--track-name^" ^"1:Original^" ^"--default-track^" ^"1:no^" ^"--language^" ^"2:jpn^" ^"--track-name^" ^"2:Japanese Subs^" ^"--default-track^" ^"2:no^" ( ^"D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/Kill la Kill - Episode 01.mkv^" ) ^"--language^" ^"0:rus^" ^"--track-name^" ^"0:full^" ^"--default-track^" ^"0:yes^" ( ^"D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Subs/[Beatrice-Raws] Kill la Kill 01 [BDRip 1920x1080 x264 FLAC].ass^" ) ^"--language^" ^"0:rus^" ^"--track-name^" ^"0:captions^" ( ^"D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Subs/captions/[Beatrice-Raws] Kill la Kill 01 [BDRip 1920x1080 x264 FLAC].captions.ass^" ) ^"--language^" ^"0:rus^" ^"--track-name^" ^"0:Gezell^" ( ^"D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Sound/[Gezell]/[Beatrice-Raws] Kill la Kill 01 [BDRip 1920x1080 x264 FLAC].mka^" ) ^"--language^" ^"0:rus^" ^"--track-name^" ^"0:Rise^" ( ^"D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Sound/[Rise]/[Beatrice-Raws] Kill la Kill 01 [BDRip 1920x1080 x264 FLAC].mka^" ) ^"--language^" ^"0:rus^" ^"--track-name^" ^"0:TrinaD ^& Cuba77^" ( ^"D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Sound/[TrinaD ^& Cuba77]/[Beatrice-Raws] Kill la Kill 01 [BDRip 1920x1080 x264 FLAC].mka^" ) ^"--language^" ^"0:rus^" ^"--track-name^" ^"0:Zendos ^& Eladiel^" ( ^"D:/Downloads/Video/Kill la Kill [BDRip] [1080p]/RUS Sound/[Zendos ^& Eladiel]/[Beatrice-Raws] Kill la Kill 01 [BDRip 1920x1080 x264 FLAC].mka^" ) ^"--track-order^" ^"0:0,0:1,0:2,1:0,2:0,3:0,4:0,5:0,6:0^"

message edited by Loro


See More: Batch merging using bat and text variables

Report •


#1
October 13, 2015 at 08:18:25
Ignore this reply, website reloaded upon post submission.
Sorry for such a late response.

message edited by Arescet


Report •

#2
October 13, 2015 at 08:19:14
I don't quite understand, is your intention to move multiple files into a folder, merge several text files into one, or something else?
A side note;
(set /p input="Press enter...")
could just be
(pause Press enter...)
Many an error has occurred using set/p with an undefined variable.

Report •

Related Solutions


Ask Question