Find files with same name in different folders

Luis Alvarado

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:

/Movies
/Movies/SomeMovieFolder1
/Movies/SomeMovieFolder2
/Movies/SomeMovieFolder3
/Movies/SomeMovieFolder...
/Movies/SomeMovieFolderN

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.

Stump

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

#!/bin/bash

movie_dir=~/Movies
subtitle_dir=~/Subtitles
log=~/log.txt

for i in "$movie_dir"/*;do
    filname="${i%.*}"
    if [ ! -e "$subtitle_dir/$filename.srt" ];then
        echo "$filename" >> "$log"
    fi
done

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

#!/bin/bash

movie_dir=~/Movies
subtitle_dir=~/Subtitles
log=~/log.txt

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"
    fi
done

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

PyCharm Import files with same name in different folders

Merge files with same name in different folders

Moving several files to different folders with same name

List all files under different folders with same name

2 folders added to PATH contain different files with the same name

How to delete 2 files with the same name from different folders?

Move files with same name in different folders to one folder

Find files with same name but different content?

Find files with same initial part of the name in two folders

Separate files by name into different folders

Python script to copy different files from one folder to different sub-folders.with same name as file name

How to differentiate files with same name with different extension from two different folders? Python

How to find files with same name but different line count in two directories?

How to rename files in different directories with the same name using find

Find files with the same name but different extensions and delete the oldest

Batch command move png files to folders same name files and folders

Windows Phone Classes with same name but different folders

Delete content of folders with same name in different subdirectories

Android DataBinding & MVVM - Using same name for layout files in different layout folders

load multiple files from different folders with same file name in bash-scipt

Configure nginx to use files and folders with the same name

rename the files with same names in different folders

Find author name in multiple files and folders in python

Java - Two classes, same name, same package but in different folders

How to find duplicate files with same name but in different case that exist in same directory in Linux?

How to solve function overloading on Octave from different folders but with the same name?

Asset Catalog: Access images with same name in different folders

Delete file with same name contained in different sub-folders

Read Multiple raster with the same name contained in different folders