Solved Need a simple looped batch file?

April 25, 2012 at 08:03:32
Specs: Windows 7

Hi, I'm currently using the mp4box software to mux my subs and videos together.

Currently, I'm going all rogue and this is my batch file:

mp4box -add "7.mp4" -add "7.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "007.mp4"
mp4box -add "8.mp4" -add "8.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "008.mp4"
mp4box -add "9.mp4" -add "9.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "009.mp4"
mp4box -add "10.mp4" -add "10.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "010.mp4"
mp4box -add "11.mp4" -add "11.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "011.mp4"
mp4box -add "12.mp4" -add "12.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "012.mp4"
mp4box -add "13.mp4" -add "13.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "013.mp4"
mp4box -add "14.mp4" -add "14.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "014.mp4"
mp4box -add "15.mp4" -add "15.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "015.mp4"
mp4box -add "16.mp4" -add "16.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "016.mp4"
mp4box -add "17.mp4" -add "17.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "017.mp4"
mp4box -add "18.mp4" -add "18.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "018.mp4"
mp4box -add "19.mp4" -add "19.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "019.mp4"
mp4box -add "20.mp4" -add "20.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "020.mp4"
mp4box -add "21.mp4" -add "21.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "021.mp4"
mp4box -add "22.mp4" -add "22.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "022.mp4"
mp4box -add "23.mp4" -add "23.srt:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "023.mp4"


I am very unfamiliar with how loops work in the bat format. I know how to do it in C++ etc, but I'm not sure how to add to a variable in a bat file.

Can anyone help me create a simple loop for this? Thank you!


See More: Need a simple looped batch file?

Report •


#1
April 25, 2012 at 08:16:14
✔ Best Answer

Assumed: Everything's in one directory
for %%a in (*.srt) do mp4box -add "%%~Na.mp4" -add "%%a:hdlr=sbtl:tx3g:lang=eng:group=2:layer=-1" -new "0%%~Na.mp4"

How To Ask Questions The Smart Way


Report •

#2
April 25, 2012 at 17:56:10

Thanks a lot! However, can you explain how the code works? What does the additional ~N actually mean? And if I have certain missing subtitles (ie. the file number may skip from 14 to 16 halfway) will the script terminate early? Cos from my original batch file without loop it will just continue on without errors.

Thank you!


Report •

#3
April 25, 2012 at 18:38:55

However, can you explain how the code works? What does the additional ~N actually mean?
Open a Command Prompt, and type the following:
for /?

And if I have certain missing subtitles (ie. the file number may skip from 14 to 16 halfway) will the script terminate early?
Because the loop operates on the srt files, it'll just "skip" any mp4 file without a matching srt file.

How To Ask Questions The Smart Way


Report •

Related Solutions


Ask Question