我正在尝试从所有 mkv 文件中删除字幕和章节。我一直在尝试找到一种方法来添加下面的批处理文件来查找章节并删除它们,但一直无法弄清楚如何编辑查找行。任何帮助都非常感谢。
@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.
)
)
)
如果我像这样重写批处理。它能完成我想要的操作,但两次检查文件就太草率了。
@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
不太确定你到底想做什么,但我认为这可以帮到你。你可以使用 findstr 来查找多个字符串(或正则表达式!)以及更多有趣的东西。我为你编写并测试了一个示例:
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"
/编辑:如果需要,添加 | 查找 -c -v“”如果您只关心 findstr 输出的行数。