How retrieve the creation date of photos with a script

prab4th picture prab4th · Aug 18, 2015 · Viewed 7.5k times · Source

What I want to do is reorganize files in my Camera Roll folder. Using the creation date I want to Put them inside folders according to Year/Month Format using their creation date.

In this answer, they explain how to make folders and organize them: https://stackoverflow.com/a/1314394/4980886

#!/bin/bash
find $PHOTO_DIR -regextype posix-extended -type d -regex '.*/[0-9]{4}/[0-9]{2}/[0-9]{2}$' |
while read dir; do
    newdir="$(echo $dir | sed 's@/\([0-9]\{4\}\)/\([0-9]\{2\}\)/\([0-9]\{2\}\)$@/\1-\2-\3@')"
    mv "$dir" "$newdir"
    rmdir "$(dirname $dir)"
    rmdir "$(dirname $(dirname $dir))"
done

But it doesn't address how to get the creation date, maybe I should get the metadata from EXIF data. How to do either?

Answer

mdn picture mdn · Jan 2, 2018

According to exiftool man page 'Renaming examples'

exiftool '-Directory<DateTimeOriginal' -d %Y/%m/%d "$dir"

and if only copying is required, there is an option:

exiftool -o . '-Directory<DateTimeOriginal' -d %Y/%m/%d "$dir"

has the same effect as above except files are copied instead of moved.