#!/bin/sh # #---makeIphoneImageNamesSensible # # Shell script for linux, Windows/Cygwin, or MacOS. # Last updated 2020-08-16 to handle images taken within the same second. # # Converts JPG files from iPhones (with stupid names like IMG_0001.JPG) # into files named with the date and time stamp from the image file. # (E.g. 20171003_151026.jpg) # # Usage: run it in a directory containing .JPG files downloaded from an # iPhone. Renames all of them. # # Copyright (C) 2017, by Charles Roth, 2017-10-04, croth (a t) thedance (d o t) net # Released under the Creative Commons Attribution-only ("BY") license. # (See https://en.wikipedia.org/wiki/Creative_Commons_license#Seven_regularly_used_licenses) #---------------------------------------------------------------------------- tmp=/tmp/makeIphoneImage$$ rm -f $tmp for x in `ls *.JPG *.jpg 2>/dev/null`; do file $x >$tmp if grep "datetime=" $tmp >/dev/null 2>/dev/null; then timestamp=`sed <$tmp "s/^.*datetime=//" | sed "s/,.*$//" | sed "s/://g" | sed "s/ /_/" | sed "s/\]//"` if test -f $timestamp.jpg; then count=1 base="$timestamp" while test -f ${base}_${count}.jpg; do count=`expr $count + 1` done mv $x ${base}_${count}.jpg else mv $x $timestamp.jpg fi else echo "Cannot find datetime in $x" >&2 fi done rm -f $tmp