Organizing photos with exif and more

I’ve recently spent a bunch of time organizing a pile of picture files in various directories. This post is about some of the utilities I’ve found more useful.

I want this structure:
├── 01
│ └── 31
│ ├── 2012-01-30_17-26-35_65.jpg
│ └── 2012-01-30_17-26-39_533.jpg
├── 02
│ └── 13
│ └── 2012-02-13_15-37-29_814.jpg
I often have this structure:
├── IMG_20171204_140837.jpg
├── IMG_20171204_140838.jpg
├── IMG_20171204_140839.jpg
├── IMG_20171213_085000.jpg
├── IMG_20171213_085021.jpg
└── IMG_20171228_110227.jpg
├── IMG_20171204_140839.jpg
├── IMG_20171213_085000.jpg
├── IMG_20171213_085021.jpg
├── IMG_20171213_085025.jpg
├── IMG_20171217_160410.jpg
└── IMG_20171217_160411.jpg

Best option…

if you files have create date stamps in the picture files, this command is the best option:
# Create Date : 2018:04:22 16:05:54
exiftool ‘-Directory<CreateDate’ -d %Y/%m/%d -r
This will set a file’s directory to reflect the CreateDate property. If there’s no such property, exiftool will do nothing.

Remove empty directories

After the “best option”, you may end up with empty directories.
find . -type d -empty -delete

Remove duplicates

fdupes -rdN <dir>+
This will keep the “first” of a set of copies and remove the rest. I’ve found it difficult to predict which will be first. I understand it’s by name but it often seems not to. Be careful for the situation where one copy is in a directory that tells you the date and another that perhaps isn’t.

Add a CreateDate tag

The date tag should look like this:
2018:04:22 16:50:28
You may have directory names that look like this:
Exiftool to the rescue
exiftool -overwrite_original ‘-CreateDate<${directory;s/ \d+$//;s/\-/:/g} 00:00:00’ \
-if ‘not $CreateDate’ -r
The main thing to remember is that exiftool is a perl script. The stuff in the ${} is just perl stuff.
You’re just creating a string that looks like: 2018:04:22 16:50:28
The same is possible with filenames:
exiftool -overwrite_original \
‘-CreateDate&lt;${filename;s/^.*_20/20/; s/(\d{4})(\d\d)(\d\d)_(\d\d)(\d\d)(\d\d).*/$1:$2:$3 $4:$5:$6/}’ \
-if ‘not $CreateDate’ -r

If all else fails

There are cases like with mp4s where I can’t set the date tag 1. In those cases, I just want to merge one directory set with another
rsync –prune-empty-dirs -a –recursive –verbose –ignore-existing \
–remove-source-files a b
This copies files from a to b, deleting the source copies from a as it goes. It won’t overwrite existing files in b. Last it does some cleanup/pruning as it goes.

  1. A least exiftool doesn’t seem to want to it. I haven’t really tried to find out why

Leave a Reply

Your email address will not be published. Required fields are marked *