Main Menu

Is it possible?

Started by edif30, May 28, 2015, 12:06:00 AM

Previous topic - Next topic

edif30

I am still searching in the documentation and other posts, but is it possible to change the DateTimeOriginal based on the DIR?  Reason is I had a camera a ways back that apparently had issues and kept resetting back to 2003.  So... I now have about 2300 files like this.  Luckily most are in individual DIR based on when I uploaded them.  That is at least a start.

/2008/2008-06-29/100_3428.jpg   100_3428.jpg   2003:01:01 13:56:00

Any suggestions are greatly appreciated

Note: I cannot use Date/Time shift because ALL of the files have nearly the same DateTimeOriginal, CreateDate, and ModifyDate and all files in the DIR are random with date shifts.  Simply shifting all by a # will not correct these.  My only hope (I think) is the directory name.

Phil Harvey

Yes, this is certainly possible, but will be a bit tricky.  One question is: How do you want to set the time part of DateTimeOriginal?

If you want to leave the time the same and just set the date, you could do this:

exiftool "-datetimeoriginal<${directory;s/.*\d{4}-\d{2}-\d{2}.*/$1:$2:$3/} ${datetimeoriginal;s/.* //}" -r DIR

- Phil
...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 ($).

edif30

Setting the time part IMO will just have to be something I let not be 100% accurate.  That's ok.  As long as I can organize via Y/M I am good.  What I was thinking is since I wouldn't want all files to have the same datetimeoriginal down to the second (would cause some confusion on my part with searches in other tools) I would like to have the time incremented by 1 second or 1 min.  This way each file is unique to a degree.  How could I accomplish this part?

Phil Harvey

Here is a post that describes how this could be done.

- Phil
...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 ($).

edif30

#4
Quote from: Phil Harvey on May 28, 2015, 07:09:51 AM
Yes, this is certainly possible, but will be a bit tricky.  One question is: How do you want to set the time part of DateTimeOriginal?

If you want to leave the time the same and just set the date, you could do this:

exiftool "-datetimeoriginal<${directory;s/.*\d{4}-\d{2}-\d{2}.*/$1:$2:$3/} ${datetimeoriginal;s/.* //}" -r DIR

- Phil



At first I couldn't figure this out.  Played around with it for a while and made progress.

With the command above I got syntax errors because there was no space between the last d{2} and the .  Fixed that and was good to a point.  My directories were the next issue and had them setup as /YYYY/YYYY-MM-DD/.  That really made things weird as you can imagine with how it wrote the DateTimeOriginal.  I don't know regex or sed and spent quite a bit of time reading and testing with online test sites.  My brain is fried now! :) 

With syntax error
exiftool '-datetimeoriginal<${directory;s/.*\d{4}-\d{2}-\d{2}.*/$1:$2:$3/} ${datetimeoriginal;s/.* //}' /mnt/nano/photo_backup/tmp/2003-11-27/
Warning: Use of uninitialized value $3 in concatenation (.) or string for Directory - /mnt/nano/photo_backup/tmp/2003-11-27/100_3428.jpg
Warning: No writable tags set from /mnt/nano/photo_backup/tmp/2003-11-27/100_3428.jpg
    1 directories scanned
    0 image files updated
    1 image files unchanged

No syntax error adding space after }
exiftool '-datetimeoriginal<${directory;s/.*\d{4}-\d{2}-\d{2} .*/$1:$2:$3/} ${datetimeoriginal;s/.* //}' /mnt/nano/photo_backup/tmp/2003-11-27/
    1 directories scanned
    1 image files updated
exiftool -datetimeoriginal 100_3428.jpg
Date/Time Original              : 2003:11:27 13:56:00
exiftool -datetimeoriginal 100_3428.jpg_original
Date/Time Original              : 2003:01:01 13:56:00

Thanks for the help!  Learned quite a lot on this scenario!  :D

Phil Harvey

Quote from: edif30 on May 29, 2015, 01:15:23 AM
With syntax error
exiftool '-datetimeoriginal<${directory;s/.*\d{4}-\d{2}-\d{2}.*/$1:$2:$3/} ${datetimeoriginal;s/.* //}' /mnt/nano/photo_backup/tmp/2003-11-27/
Warning: Use of uninitialized value $3 in concatenation (.)

Ah, sorry.  I forgot to capture the matching numbers:  s/.*(\d{4})-(\d{2})-(\d{2}).*/$1:$2:$3/

Adding the space caused the match to fail, so the substitution doesn't occur and the time will be based on the remaining digits in the file name.

- Phil
...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 ($).