瀏覽單個文章
ericshliao
Advance Member
 

加入日期: Aug 2004
文章: 334
問ChatGPT給的答案:

Skip to content
Open sidebar
You said:
Write a batch file for Windows. In all subdirectories, for each .mkv and .srt pair, run mk.exe.
ChatGPT said:
Here’s a Windows batch file that recursively searches through all subdirectories for .mkv and .srt files with matching base names, then runs your program mk.exe for each matching pair.

-----------------------------------------------------------
@echo off
setlocal enabledelayedexpansion

rem === Search recursively for all .mkv files ===
for /r %%A in (*.mkv) do (
set "mkvfile=%%~A"
set "basename=%%~nA"
set "folder=%%~dpA"
set "srtfile=!folder!!basename!.srt"

if exist "!srtfile!" (
echo Found pair:
echo MKV: !mkvfile!
echo SRT: !srtfile!
echo Running mk.exe...
mk.exe "!mkvfile!" "!srtfile!"
echo.
)
)

echo Done.
pause
🧩 How it works
for /r %%A in (*.mkv) — recursively finds all .mkv files.

For each .mkv, it:

Extracts the base name (%%~nA).

Constructs the .srt file path using the same folder and base name.

Checks if that .srt exists.

If yes, runs:

mk.exe "full\path\to\file.mkv" "full\path\to\file.srt"
Outputs progress to the console.

💡 Optional improvements
If you want to redirect mk.exe output to a log file:

mk.exe "!mkvfile!" "!srtfile!" >> "mk_log.txt" 2>&1
If mk.exe is not in PATH, specify the full path:

"C:\path\to\mk.exe" "!mkvfile!" "!srtfile!"
Would you like it to skip already processed pairs (e.g., if output exists or logged), or just process everything each time?



No file chosenNo file chosen
舊 2025-10-06, 05:43 PM #4
回應時引用此文章
ericshliao離線中