Sort photos with CreateDate in wrong format (MM:DD:YYYY)?

Started by 73b0e8e1, October 16, 2020, 12:55:50 PM

Previous topic - Next topic

73b0e8e1

I am using ExifTool on Linux and have run into a problem with photos coming off an old feature phone. The creation date on those photos are in the MM:DD:YYYY format vs the correct YYYY:MM:DD format which has thrown a wrench in my organization automation. I have two folders, unsorted & sorted, and I am sorting the photos by year. The command I am using is below and has worked well for the most part.


Sort by year into folders
exiftool -d %Y '-filename</home/user/sorted_photos/${CreateDate}/%f%+c' -r /home/user/unsorted_photos


Questions

  • Can I use this program to change all of the photos in question from MM:DD:YYYY to YYYY:MM:DD?
  • Is there a way to get ExifTool to look for the YYYY deeper in the creation date string for the MM:DD:YYYY photos?
  • Is is possible to put together a command that will handle both MM:DD:YYYY and YYYY:MM:DD photos at once and move them to the correct year folder?

Thanks in advance for any help this community can provide! ExifTool is an amazing program and has already saved me countless days and has helped me to automate my photo organization.

Phil Harvey

#1
This command should fix the CreateDate formatting:

exiftool "-createdate<${createdate;s/^(\d{2}):(\d{2}):(\d{4})/$3:$1:$2/ or $_ = undef}" DIR

The command will only rewrite files which have an incorrect CreateDate value.

Note this assumes the format is as you said (with colon separators between the date fields).

- Phil

Edit: Added missing closing brace (}).
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

73b0e8e1

Thanks for the quick reply Phil! As soon as you mentioned "Note this assumes the format is as you said (with colon separators between the date fields)." I went and checked the original files. Sure enough there is a period between date fields and not colons. The way the data is actually presented is 05.29.2009 18:12, I was so caught up in the different order I completely missed the periods. How should the command look for periods instead colons, or does that break everything?

StarGeek

Replace the colons with \.
s/^(\d{2})\.(\d{2})\.(\d{4})/$3:$1:$2/
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

73b0e8e1

I am getting the following error on the files in question. I failed to mention I am using version 12.08 of ExifTool, and these are .JPG files. If there is any other information you need please let me know.

Error
Warning: Substitution pattern not terminated for 'createdate' - /home/user/unsorted_photos/IMG_0900.JPG
Warning: No writable tags set from /home/user/unsorted_photos/IMG_0900.JPG

StarGeek

The closing brace was missing from the original command.  Try
exiftool "-createdate<${createdate;s/^(\d{2})\.(\d{2})\.(\d{4})/$3:$1:$2/ or $_ = undef}" DIR

Sidenote: I really have to put a post it above my computer to remind me of the or $_ = undef trick.  I keep forgetting about it.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

73b0e8e1

That worked perfectly! Thank you both for all of your help. I have a few things more things I need to figure out with this tool but am well on my way to organizing my photos! I am really impressed with the capabilities of this tool, documentation provided, and more importantly the community and developer involvement on this forum!