批处理脚本,查找,替换和输出新文件,每次加一

时间:2019-02-14 16:21:52

标签: batch-file mkv

我正在使用mkvmerge编辑一堆文件,我正在这样做:

来自original-001.mkv的视频与来自audio-001.mkv的音频混合,并添加来自sub-001.mkv的字幕。

我正在创建一堆.bat脚本,并使用notapad ++查找和替换功能来做到这一点:

找到001并替换为002,另存为002.bat并继续。

基本上,总会有一个名为001.bat的基本文件

这真是个好主意,可以自动执行此Notepad ++部分。 查找所有字符串“ 001”,替换为“ 002”,另存为002.bat 找到“ 002”,替换为“ 003”,另存为003.bat。

最多300。

最后我要做的是另一个脚本: 致电001.bat 致电002.bat,依此类推。 如果我的文件不存在,那就没有问题。

可以在Windows上使用批处理脚本吗?

编辑以添加代码作为我现在要去的方式: 001.bat的示例

"C:/Program Files/MKVToolNix\mkvmerge.exe" --ui-language en --output ^"F:\original\original-001 ^(1^).mkv^" --language 0:eng --default-track 0:yes --language 1:eng --default-track 1:yes ^"^(^" ^"F:\original\original-001.mkv^" ^"^)^" --no-video --language 1:por ^"^(^" ^"F:\BR001.mp4^" ^"^)^" --track-order 0:0,0:1,1:1

我有这个(但它是powershell)

powershell -Command "(gc 001.bat) -replace '001', '002' | Out-File 002.bat"
powershell -Command "(gc 002.bat) -replace '002', '003' | Out-File 003.bat"
powershell -Command "(gc 003.bat) -replace '003', '004' | Out-File 004.bat"
powershell -Command "(gc 004.bat) -replace '004', '005' | Out-File 005.bat"
powershell -Command "(gc 005.bat) -replace '005', '006' | Out-File 006.bat"
and so on

最后我用这个:

call 001.bat
call 002.bat
call 003.bat
call 004.bat
call 005.bat
call 006.bat
and so on

但是我都是手工完成的,所以自动化的方式对于mkvtoolnix的所有输出都是惊人的,因为我可以使用高级重命名器将所有情节更改为001、002 ..等,然后通过filebot修改正确的季节和剧集列表。

2 个答案:

答案 0 :(得分:1)

我怀疑,生成300个几乎相同的批处理文件是一个好主意。仅使用一个并循环显示您的数字:

@echo off
setlocal 

for /l %%i in (1,1,300) do call :processFile %%i
goto :eof

:processFile
set "number=000%1"
set "number=%number:~-3%"
echo %number%: original-%number%.mkv audio-%number%.mkv sub-%number%.mkv
REM insert your mux command here

答案 1 :(得分:0)

你在这里。

转到“ **并在**此处**进行填充”。

您将在这里搜索并替换新文件。

    @echo off

    :: This is the meat of the whole script..
    :: increment a number from 1 to 300
    for /L %%n in (1,1,300) do call :check_copy_file %%n
    goto :eof

    :: lines here will never execute because goto :eof is like "return" to cmd.exe

    :: ------------------------------------------------------
    :: function -- check_copy_file
    :: purpose  -- takes an input number, increments it, pads it with zeros 
    ::          -- copies original to new number name
    ::          -- ** and does stuff to it ** this is where you search and replace..
    :: ------------------------------------------------------
    :check_copy_file
    Set existing_file_num=%1
    Set /a new_file_num=%existing_file_num% +1

    call :pad_with_zeros existing_file_num %existing_file_num%
    call :pad_with_zeros new_file_num %new_file_num%

    :: ** if there isn't a batch file to copy, return
    if not exist %existing_file_num%.bat echo %existing_file_num%.bat doesn't exist!&& goto :eof

    :: copy (for instance 001.bat to 002.bat)
    copy %existing_file_num%.bat %new_file_num%.bat

    :: ** and does stuff to it ** RIGHT HERE ** 
    :: muck with the contents of %new_file_num%.bat
    echo mucky mucking with file %new_file_num%.bat

    goto :eof

    :: ---------------------------------------
    :: function -- pad_with_zeros
    :: purpose  -- adds up to two 0s as needed
    :: ---------------------------------------
    :pad_with_zeros
    Set input_var=%1
    Set input_val=%2
    if "%input_val:~2,1%"=="" Set input_val=0%input_val%
    if "%input_val:~2,1%"=="" Set input_val=0%input_val%
    Set %input_var%=%input_val%

    goto :eof