Skip to content

Instantly share code, notes, and snippets.

@farshidhss
Created September 6, 2020 11:16
Show Gist options
  • Select an option

  • Save farshidhss/d0a725c8b98900af1d59f0ada3e81ec8 to your computer and use it in GitHub Desktop.

Select an option

Save farshidhss/d0a725c8b98900af1d59f0ada3e81ec8 to your computer and use it in GitHub Desktop.
Add filename to the title metadata for all video files in a directory
#!/usr/local/bin/zsh
for entry in *."$1"
do
Filename=${entry%.*}
echo "setting title -> " $Filename
FileTitle=$(exiftool -s -Title "$entry" | awk '{print $3}');
echo "file title: " $FileTitle
if [ "$FileTitle" = "$Filename" ]; then
echo "File title is the same as filename, skipping..."
else
exiftool -P -overwrite_original -Title="$Filename" $entry
fi
done
@farshidhss
Copy link
Author

farshidhss commented Sep 6, 2020

This needs exiftool which can be downloaded from https://exiftool.org/
Call this file inside a folder with all your video files with the extension of the files. For example, if extension is mp4 then run:
-> ./setTitleFromFilename.sh mp4

Should also work for any other type of file that has Title in metadata.

@Xuchilbara
Copy link

But how can this be done? I copy exiftool to the files folder, I run it and the black CMD window opens, but it doesn't let me execute any command...

I'm trying to batch write the Title in the metadata from the file names for a few MP4 video files... I'm doing it now with Mp3tag, but I still would like to know how to do it with exiftool.

Thank you.

@farshidhss
Copy link
Author

farshidhss commented Dec 29, 2025

I suggest first open a terminal session and go to the folder where your files are stored. Then just test to see if exiftool actually runs inside your folder. If it did run then do a chmod +x setTitleFromFilename.sh to be able to execute the script then run the command ./setTitleFromFilename.sh mp4

  • make sure you have backup of your files just in case anything goes wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment