Rename .srt file based on .mkv in same folder

@Leo how could we do rename automation withing the same folder using the filename of a video file (mkv) to rename a subtitles file (srt) plus adding an language designator (.ENG)? To illustrate:

Files within the same folder
abc.mkv
123.srt

By selecting 123.srt and a button click we want to be renamed to abc.ENG.srt.

Similarly in flat-view, selecting multiple .srt files, these to be renamed based on the video-filename (usually mkv) contained in the same folder (condition: the folder contains only one video file).

Thank you for a great piece of software and always awesome support!

Rename preset:

For reference, the rename script (JScript):

function OnGetNewName(getNewNameData)
{
	var mkvName = "";
	var dir = DOpus.FSUtil.ReadDir(getNewNameData.item.path);
	while(!dir.complete)
	{
		var item = dir.Next();
		if (item.ext.toUpperCase() == ".MKV")
		{
			if (mkvName == "")
				mkvName = item.name_stem;
			else
				return; // Too many MKV files.
		}
	}

	if (mkvName == "")
		return; // No MKV file.

	return mkvName + ".ENG" + getNewNameData.newname_ext;
}
1 Like

@Leo the JS code works fine within the rename presets. I have tried to place it in a button (following How to use buttons and scripts from this forum - #2 by Leo) by selecting Script Type "JScript" and pasting the code there but no luck. Any special instructions please?

See Using a Rename Preset outside the Rename Dialog

1 Like

@Leo Great! Thank you!