Affichage des articles dont le libellé est dates. Afficher tous les articles
Affichage des articles dont le libellé est dates. Afficher tous les articles

vendredi 17 décembre 2010

Fixing modification dates on photos using the creation date in the photo file (set by the camera)

I have a large collection of photos, several dozens of Gb and I accidentally copied them without preserving the orginal creation dates.

Every photo you take has a date set in the file by the camera in what is called exif metadata. Some cameras can also record the exact coordinates where the photo was taken ... anyway, I needed to fix those dates. I also like to keep the files in a year/month/day folder structure.

So, here is my script:

#!/bin/sh

DATE=`exiftool "$1" | grep 'Create Date' | sed -e 's/.*: //;s/://g;s/..$//;s/ //g'`

DEST=`echo $DATE | sed 's@^\(....\)\(..\)\(..\).*@/media/shared/Pictures/\1/\2/\3/@'`
touch -t $DATE "$1"

if [ -d "$DEST" ]; then
cp -an "$1" "$DEST"
else
mkdir -p "$DEST"
cp -an "$1" "$DEST"
fi