Looking to use CLI to automatically merge external subtitles to MKV if they are in the same folder

Hello! New to the forum and use MKVToolNix a lot but would like to automate my workflow a bit. Looking for a solution to one or both of these scenarios:

1.) I’d like to automatically merge subtitles to MKV files if they are in the same directory and have the same name. For example, merge:

  • Will.Trent.S01E01.mkv
  • Will.Trent.S01E01.srt

2.) Even better if the subtitle file itself doesn’t have the same name, but is in a folder with the same name as the MKV file.

  • /media/Will.Trent.S01E01.mkv
  • /media/Will.Trent.S01E01/01_eng.srt

Does anyone have a script that does any of these things? Thank you very much!

For question nō.1 only:

CMD:

for %Z in ("*.mkv") do mkvmerge.exe ^
  -o "OK\%~nZ.mkv" "%~Z" "%~dpnZ.srt"

BATCH file:

for %%Z in ("*.mkv") do mkvmerge.exe ^
  -o "OK\%%~nZ.mkv" "%%~Z" "%%~dpnZ.srt"