Sorting a photo archive with exiftool
The archive from the backup post had a different problem: folders called DCIM_old, phone 2019 and New folder (3). I wanted one tree, year/month/, with file names that sort by when the picture was taken. exiftool does all of it.
Dry run first
exiftool has a pseudo-tag, TestName, that prints what a rename would do without touching anything:
cd ~/photos-sorted
exiftool '-TestName<DateTimeOriginal' -d '%Y/%m/%Y-%m-%d_%H%M%S%%-c.%%e' -r ~/incoming
%%-c adds a counter if two files end up with the same name (burst shots), and %%e keeps the original extension. When the output looks right, change TestName to FileName and the files are moved into the tree below the current directory.
Files without a capture date
Film scans and some old phone pictures have no DateTimeOriginal. You can give exiftool a fallback: when several assignments target the same tag, the last one that has a value wins.
exiftool '-FileName<FileModifyDate' '-FileName<DateTimeOriginal' \
-d '%Y/%m/%Y-%m-%d_%H%M%S%%-c.%%e' -r ~/incoming
A camera that was an hour behind
One camera never got the summer time change and spent a whole summer an hour behind. Shifting all date tags by one hour:
exiftool '-AllDates+=1' -r ~/incoming/summer-2021
By default exiftool keeps a copy of every changed file with _original appended. Annoying, but I left it on until I trusted the commands, then deleted the copies with exiftool -delete_original!.