Skip to content

Instantly share code, notes, and snippets.

@dmcallejo
Created January 5, 2024 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmcallejo/f426f9eaa9a968e18c66f1177e9894b2 to your computer and use it in GitHub Desktop.
Save dmcallejo/f426f9eaa9a968e18c66f1177e9894b2 to your computer and use it in GitHub Desktop.
Filename date to EXIF date
#!/bin/bash
FILES=$1*.*g
REGEX='.*(\d{4})-?(\d{2})-?(\d{2})(?>-|_|\s(?>at\s)?)(\d{2})(?>\.|-)?(\d{2})(?>\.|-)?(\d{2}).*'
for f in $FILES
do
echo -n "$f:"
date=$(echo "$f" | perl -ne 'print if m/'"$REGEX"'/' | perl -pe 's/'"$REGEX"'\..*/"$1:$2:$3 $4:$5:$6"/g')
if [ -n "$date" ]; then
echo $date
exiftool -AllDates="$date" "$f"
else
echo "No Date"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment