This is a tricky one. I need to do the following using 2 folders, the movie folder and the subtitle folder:

  1. Search for every movie inside the movie folder, for each file it finds, grab the files name and try to search for it in the subtitle folder.

  2. If the file is found do nothing. If the file is not found, output the file name to a log file that will collect all movies that do not have a subtitle.

The movie folder has the following format:


And inside each movieFolder is the actual movie (Each movie is in it's own folder inside the Movie folder.

The subtitle folder has all subtitles in the same place. In the subtitles folder.

My thinking would be 2 find commands looped together using a while. This would be a shell script (bash).

Movies are MP4 or MKV formats. Subtitles are SRT format.

  • Are all the movies the same format? Likewise, the subtitle files? If the movies all end in .mp4 and the subtitles all end in .srt (or whatever - the actual extension doesn't matter), then that would simplify things. – evilsoup May 5 '13 at 16:30
  • @evilsoup updated to include your questions. – Luis Alvarado May 5 '13 at 16:50

If filenames of the movies and subtitles files match and only the extensions differ, something like this should work.



for i in "$movie_dir"/*;do
    if [ ! -e "$subtitle_dir/$filename.srt" ];then
        echo "$filename" >> "$log"

EDIT For when each movie file is in it's own folder then try:



find "$movie_dir" -type f -name "*.mp4" -o -name "*.mkv" | while read i;do
    filename="$(basename "${i%.*}")"
    if [ ! -e "$subtitle_dir/$filename.srt" ];then
        echo "$filename" >> "$log"

This second way should work regardless of the movie folder structure, again as long as the filenames are the same.

  • Updated a minor detail I forgot to mention. Each movie is inside it's own folder which are inside the movie folder. – Luis Alvarado May 5 '13 at 17:31
#!/usr/bin/perl -w
use strict;
use File::Find;
use File::Basename qw( basename );

my $movies_dir = "/home/user/movies";
my $subs_dir = "/home/user/subs";
my $log = "./movie-log";

my %options;
my %subs = map { basename($_) =~ s/\.[^.]+$//r, 1 } <$subs_dir/*>;
open LOG, '>>', $log or die "Can't open $log: $!\n";

$options{wanted} = sub {
    my $movie = s/\.[^.]+$//r;
    if ( -f && /\A.*\.(mp4|mkv)\z/i ) {
        exists $subs{$movie} or
        print LOG "$_\n";

$options{preprocess} = sub {
    sort @_;

find (\%options, $movies_dir);

Script will create a log file named movie-log in current directory, containing the names of movies that doesn't have subtitles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.