Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How retrieve the creation date of photos with a script

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?

like image 933
prab4th Avatar asked Aug 18 '15 01:08

prab4th


People also ask

How can I find the original date of a photo?

In your PC's File Explorer, just click right on the image file and select “Properties / Details.” There you can see “Date Taken, a.k.a. Date Time Original.

How do I find the original creation date of a file?

To do that you can go to file explorer, click on documents, Click View, add column, and check “Date created” and “Date modified” both. This will show both in documents folder as well.

How do I import photos and keep the original creation date in Apple photos?

Use the File > Export command and export the phots as the unmodified original, if you want to keep the original file creation date. If you export an edited version Photos will render a new file with the adjustments applied, and this new file will have a new a new creation date.


1 Answers

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.

like image 56
mdn Avatar answered Sep 19 '22 04:09

mdn