#!/bin/bash # Sort pictures by date # # filename list working file #if [ -z "$1" ] # then # echo usage: SoPi picturedirectory # exit #fi FN_List="SoPiList.out" EXIF_List="SoPiEXIF.out" Sorted_EXIF_List="SoPiEXIFS.out" PictureList="PictureList.txt" Pic_PATH=${1:-"Fotos"}"/" echo $Pic_PATH #Pic_PATH="$1/" # make sure file PictureList does not exist! To avoid overwriting existing data if [ -s "$PictureList" ] then echo ***Error: File $PictureList already exists exit fi # List all pictures in the current directory and sub-directories echo Finding files... find "$Pic_PATH" -type f > "$FN_List" # read this file and add EXIF data echo Finding EXIF data... while read filename do # grep the line that contains the date the picture was taken, ignore error messages #### EXIF_Value=`exif -t DateTimeOriginal "$filename" 2>/dev/null | grep -H --label="$filename" Value` EXIF_Value=`exiv2 -g Exif.Photo.DateTimeOriginal -Pv print "$filename" 2>/dev/null` # stat uses "-" in the date, exiv2 ":" EXIF_Value=`echo $EXIF_Value | sed -e {s/:/-/} -e {s/:/-/}` # if no picture date available use last modification date of file if [ -z "$EXIF_Value" ] then EXIF_Value=`stat --printf="%y" "$filename"` fi echo -e \""$filename"\" \"$EXIF_Value\" >> $EXIF_List done < "$FN_List" # sort by date, ignore separation characters in date (":" for EXIF, "-" for stat) echo Sorting filenames by date, then filename... sort --field-separator=" " --key=2 -d -o $Sorted_EXIF_List $EXIF_List echo Creating file $PictureList ... echo 'var pictureString = (` \' > "$PictureList" mawk -F\" '{printf "
%s
\n", $2, $4}' $Sorted_EXIF_List >> "$PictureList" echo '`);' >> "$PictureList" echo cleaning up ... rm -f $EXIF_List rm -f $FN_List rm -f $Sorted_EXIF_List echo ...done exit