1

I am trying to remove subtitles and chapters from all my mkv files. I've been trying to find a way to add the below batch file to also look for chapters and remove them but haven't been able to figure out how to edit the find line. Any help is very much appreciated.

@echo off
cls
set rootfolder=C:\
echo Enumerating all MKVs under %rootfolder%
echo.
for /r %rootfolder% %%a in (*.mkv) do (
    for /f %%b in ('mkvmerge -i "%%a" ^| find /c /i "subtitles"') do (
        if [%%b]==[0] (
            echo "%%a" has no subtitles
        ) else (
            echo.
            echo "%%a" has subtitles
            mkvmerge -q -o "%%~dpna (No Subs)%%~xa" -S "%%a"
            if errorlevel 1 (
                echo Warnings/errors generated during remuxing, original file not deleted
            ) else (
                del /f "%%a"
                echo Successfully remuxed to "%%~dpna (No Subs)%%~xa", original file deleted
            )
            echo.
        )
    )
)

If I rewrite the batch like this. It does what I want but it is sloppy going through the files twice.

@echo off
cls
set rootfolder="D:\uTorrent\Completed Downloads"
echo Enumerating all MKVs under %rootfolder%
echo.
for /r %rootfolder% %%a in (*.mkv) do (
    for /f %%b in ('mkvmerge -i "%%a" ^| find /c /i "subtitles" ') do (
        if [%%b]==[0] (
            echo "%%a" has no subtitles
        ) else (
            echo.
            echo "%%a" has subtitles
            mkvmerge -q -o "%%~dpna (No Subs)%%~xa" -S --no-chapters "%%a"
            if errorlevel 1 (
                echo Warnings/errors generated during remuxing, original file not deleted
            ) else (
                del /f "%%a"
                echo Successfully remuxed to "%%~dpna (No Subs)%%~xa"
            )
            echo.
        )
    )
)
set rootfolder="D:\uTorrent\Completed Downloads"
echo Enumerating all MKVs under %rootfolder%
echo.
for /r %rootfolder% %%a in (*.mkv) do (
    for /f %%b in ('mkvmerge -i "%%a" ^| find /c /i "chapters" ') do (
        if [%%b]==[0] (
            echo "%%a" has no chapters
        ) else (
            echo.
            echo "%%a" has chapters
            mkvmerge -q -o "%%~dpna (No Chapters)%%~xa" -S --no-chapters "%%a"
            if errorlevel 1 (
                echo Warnings/errors generated during remuxing, original file not deleted
            ) else (
                del /f "%%a"
                echo Successfully remuxed to "%%~dpna (No Chapters)%%~xa"
            )
            echo.
        )
    )
)
pause

1 Answers1

0

Not exactly sure on what you're trying to do exactly, but I think this can help you. You can use findstr to look for multiple strings (or regular expressions!) and much more interesting things. I wrote and tested an example for you:

c:\tmp\findtest>dir /b
x.txt
y.txt
z.txt

c:\tmp\findtest>type x.txt y.txt z.txt

x.txt:
"this is x"

y.txt:
"this is y"

z.txt:
"this is z"

c:\tmp\findtest>findstr /i /r "x y" *
x.txt:"this is x"
y.txt:"this is y"

/edit: and if needed, add | find -c -v "" to that if you only care about the line count of the findstr output.

SadBunny
  • 1,416