FILE=$1
TYPE=$(file "$FILE" | grep JPEG)
if [ -n "$TYPE" ]; then
- ASCII_DATE=$(exif -m -t 'Date and Time' "$FILE") # 2010:07:02 08:36:20
+ FIELD_NAME='Date and Time'
+ ASCII_DATE=$(exif -m -t "$FIELD_NAME" "$FILE") # 2010:07:02 08:36:20
+ if [ $? -ne 0 ]; then # use similar field, e.g. 'Date and Time (original)'
+ FIELD=$(exif -m "$FILE" | grep "$FIELD_NAME" | head -n1)
+ FIELD_NAME=$(echo "$FIELD" | sed 's/\t.*//')
+ if [ -z "$FIELD_NAME" ]; then
+ echo "$FILE has no stored date"
+ ASCII_DATE=""
+ else
+ echo "$FILE using date from $FIELD_NAME"
+ ASCII_DATE=$(exif -m -t "$FIELD_NAME" "$FILE") # 2010:07:02 08:36:20
+ fi
+ fi
DATE=$(echo "$ASCII_DATE" | sed 's/:/./g' | sed 's/ /./g')
if [ -z "$DATE" ]; then
echo "$FILE has no stored date"