Skip to content

Instantly share code, notes, and snippets.

@hfiguiere
Created October 16, 2022 21:55
Show Gist options
  • Save hfiguiere/08c50970f38d470b59e0535cb122e141 to your computer and use it in GitHub Desktop.
Save hfiguiere/08c50970f38d470b59e0535cb122e141 to your computer and use it in GitHub Desktop.
Image Sorter
#/bin/sh
set -e
# very hackish
# Change the directory name below
# Make sure you have exiftool installed
#
# Will create a folder YYYYMMDD and move the image into it
# based on Exif, or at worse on the file date.
#
# Tested with a dump of iPhone pictures and movies (JPEG and MOV)
for i in Hubert\’s\ iPhone/*; do
folder=`exiftool -EXIF:DateTimeOriginal -s3 -d %Y%m%d "$i"`
if [ -z "$folder" ] ; then
folder=`exiftool -CreationDate -s3 -d %Y%m%d "$i"`
fi
if [ -z "$folder" ] ; then
folder=`exiftool -CreateDate -s3 -d %Y%m%d "$i"`
fi
if [ -z "$folder" ] ; then
folder=`exiftool -FileModifyDate -s3 -d %Y%m%d "$i"`
fi
if [ ! -z "$folder" ] ; then
if [ ! -d $folder ] ; then
mkdir $folder
fi
echo "Moving $i to $folder"
mv "$i" $folder
else
echo "Empty folder for $i"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment