Page 1 of 1

run mkvmerge through every file inside folder [SOLVED]

Posted: 10 Jul 2022 03:12
by AlphaInc.
Hello everybody,

not sure if this is the right sub for my question but still I'm taking the shot.
I want to set up a batch script which runs through my entire folder and use mkvmerge to add a custom audio track to every mkv file inside this folder.
This is my script:

Code: Select all

@echo on

rem set preperations
setlocal DisableDelayedExpansion

for %%A in ("*720p.mkv") do (
	set "name=%%A"
	setlocal EnableDelayedExpansion
	C:\System\MKVToolNix\mkvmerge.exe -o new_!name!.mkv -A "%%A" C:\System\MKVToolNix\src\audio.wav
)
When I run the script, this is the output I get:

Code: Select all

C:\MKVToolNix_Input\ToDo>(
set "name=Move name 1 - 720p.mkv"
 setlocal EnableDelayedExpansion
 C:\System\MKVToolNix\mkvmerge.exe -o new_!name!.mkv -A "Move name 1 - 720p.mkv" C:\System\MKVToolNix\src\audio.wav
)
mkvmerge v68.0.0 ('The Curtain') 64-bit
Fehler: Die Datei »name« konnte nicht zum Lesen geöffnet werden: open file error.

Re: run mkvmerge through every file inside folder

Posted: 10 Jul 2022 04:33
by aGerman
I don't know anything about mkvmerge. However there are some obvious things that are going to lead to errors anyway.

1) Don't call setlocal in a loop without endlocal. You can't nest setlocals endlessly.
2) Your name variable contains e.g.
Move name 1 - 720p.mkv
This makes new_!name!.mkv expand to
new_Move name 1 - 720p.mkv.mkv
Not only that this creates a double extension. You didn't quote this new name in the commad line even though it contains spaces.

I think neither EnableDelayedExpansion nor the name variable are actually necessary.

Code: Select all

for %%A in ("*720p.mkv") do (
	C:\System\MKVToolNix\mkvmerge.exe -o "new_%%~nA.mkv" -A "%%A" C:\System\MKVToolNix\src\audio.wav
)
Perhaps this will resolve your problem. I can't test it though.

Steffen

Re: run mkvmerge through every file inside folder

Posted: 10 Jul 2022 04:51
by AlphaInc.
Thank you, that worked great.