#!/bin/bash
# You need exiftool.
#
# To sort all *.JPG recursively u can use:
#   find ./ -iname '*.jpg' -exec ./picsort.bash {} \;


FILE_NAME="$*";
TIME_STAMP=$(exiftool "$FILE_NAME" | grep "Date/Time Original" | cut -c 35- | cut -c -11);

if [ "$TIME_STAMP" = "" ]; then
        TIME_STAMP=$(exiftool "$*" | grep "File Modification Date/Time" | cut -c 35- | cut -c -11);
                if [ "$TIME_STAMP" = "" ]; then
                        echo "$FILE_NAME : no timestamp found. Moving to ./0000.";
                        mkdir -p "./0000";
                        mv -v "$FILE_NAME" "./0000";
                fi;
fi;

YEAR=$(echo $TIME_STAMP | cut -c -4);
MONTH=$(echo $TIME_STAMP | cut -c 6- | cut -c -2);
DAY=$(echo $TIME_STAMP | cut -c 9-);

mkdir -p "./$YEAR-$MONTH-$DAY";
mv -v "$FILE_NAME" "./$YEAR-$MONTH-$DAY";

exit 0;
Powered by MediaWiki