Option A: Use the {folder} binding to find nearby files
Use Case: Use a Plain File Mode custom Preset to rename the given files so that the each file is assigned the same file name as the largest file in the same folder.Format: Select all
{ folder.files.max{ it.length() }.nameWithoutExtension }{ subt }
Option B: Use the {mediaFile} binding to find the primary media file
The {mediaFile} binding can also be used to find the primary video file for a given subtitle file, from the same folder or parent folder, which can then be used to rewrite the subtitle file path:Format: Select all
{ mediaFile.dir }/{ mediaFile.nameWithoutExtension }{ subt }
{mediaFile.dir} is the parent folder of the primary video file, and so the subtitle file will be moved there. {mediaFile.nameWithoutExtension} will ensure that the subtitle file will be named after the primary video file, so that the names match exactly. If subtitles were originally organized into Subs or Subtitles sub-folders then FileBot will delete these sub-folders automatically if left behind empty.
Option C: Use the name of the n-th video file in the folder to rename the n-th subtitle file in the folder
Use Case: If files are in order, then the n-th video file typically matches the n-th subtitle file, and if that assumption indeed holds true for your files, then matching video / subtitle files is trivial:Format: Select all
{
def index = folder.listFiles{ it.hasExtension(ext) }.indexOf(f)
def videoFile = folder.listFiles{ it.video }.get(index)
videoFile.nameWithoutExtension
}
Console Output: Select all
$ filebot -rename *.srt --db file --format "{ def index = folder.listFiles{ it.hasExtension(ext) }.indexOf(f); def videoFile = folder.listFiles{ it.video }.get(index); videoFile.nameWithoutExtension }"
Rename files using [Plain File]
[MOVE] from [1.srt] to [Alias.1x01.srt]
[MOVE] from [2.srt] to [Avatar.2009.srt]