run mkvmerge through every file inside folder [SOLVED]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
AlphaInc.
Posts: 21
Joined: 15 Apr 2021 08:15

run mkvmerge through every file inside folder [SOLVED]

#1 Post by AlphaInc. » 10 Jul 2022 03:12

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.
Last edited by AlphaInc. on 10 Jul 2022 04:54, edited 1 time in total.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: run mkvmerge through every file inside folder

#2 Post by aGerman » 10 Jul 2022 04:33

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

AlphaInc.
Posts: 21
Joined: 15 Apr 2021 08:15

Re: run mkvmerge through every file inside folder

#3 Post by AlphaInc. » 10 Jul 2022 04:51

Thank you, that worked great.

Post Reply