Skip to content

Instantly share code, notes, and snippets.

@deltaepsilon
Created July 2, 2023 23:26
Show Gist options
  • Save deltaepsilon/56099a42eb2f2fa8a61f21abf0454bc8 to your computer and use it in GitHub Desktop.
Save deltaepsilon/56099a42eb2f2fa8a61f21abf0454bc8 to your computer and use it in GitHub Desktop.
Pull EXIF Create Date using exiftool and prefix the filename with YYYYMMDD_HHMMSS_*
#!/bin/bash
## Installation: Add to path and call with `dates` or `dates <directory>`
## Bard prompt: "write me a script to use exiftool to prefix mp4 filenames with their timestamps"
if [[ $1 ]]; then
echo "The first argument exists"
current_directory=$(pwd)/$1
else
current_directory=$(pwd)
fi
files=$(find $current_directory -name "*.*")
for file in $files; do
echo $file
done
read -p "Would you like to prefix these filenames 👆 with YYYYMMDD_HHMMSS? [y/n]"
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Running the date prefixer..."
else
echo "Come back later!"
exit
fi
# Iterate over the list of mp4 files.
for file in $files; do
timestamp=$(exiftool -d '%Y%m%d_%H%M%S' -CreateDate $file)
timestamp=$(sed 's/[^0-9_]//g' <<< $timestamp)
# Prefix the filename with the timestamp.
filename=$(basename $file)
new_filename="./$timestamp"_"$filename"
# Rename the mp4 file.
echo $new_filename
# mv $file $new_filename
done
echo "The script has finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment