I'm looking for some command / script to scan my designated folder, merge the srt files (same name as video) with avi/mp4/mkv files to get mkv files, and then delete the original files (video AND subtitle).
Now I have this code (not mine, from some authors I combined):
@echo off
for /R %%A IN (*.mkv *.avi *.mp4) do (
"C:\Program Files\MKVToolNix\mkvmerge.exe" -o "%%~nxA_CZ.mkv" "%%~A" "%%~nA.srt"
if errorlevel 1 (
echo Warnings/errors generated during remuxing, original file not deleted
) else (
del /f "%%A" "%%~nA.srt"
echo Successfully remuxed to "%%~dpna (No Subs)%%~xa", original file deleted
)
echo.
)
)
)
Which kind of works, but I have a few problems.
The /R
parameter isn't working, don't know why, but when I place it in a folder with subfolders it only scans the srt files in it and I get a "Can't open" error. (This error also appears for files in a single folder but in the end it does what I need.)
Any idea how to fix my problem?
FOR /F "TOKENS=*" %%A IN
loop using the('DIR /A-D /B /S "C:\Root"')
and then use the output of that with some logic to pick out of the.mp4
,.avi
, and.mkv
files with theDO
command. Using something likeIF [%%~XA]==[.mkv]
, etc. and then tell it to do themkvmerge.exe
operation from there accordingly. With some testing you can complete this so get to work and ping me back if you'd like an answer explaining but take your stab at it with that quick idea.