Renaming file using DateTimeOriginal, or FileModifyDate if DTO doesn't exist

Started by jomk, November 11, 2013, 05:46:21 PM

Previous topic - Next topic

jomk

A number of my images are scans or old jpgs with no EXIF data, and i want to rename them all with a std date format.

Eventually worked out to do this in a .bat file

exiftool -P -overwrite_original_in_place -r -ext cr2 -ext jpg -iptc:caption-abstract^<filename d:\testX >line1o.txt
exiftool -if "not $DateTimeOriginal" -filename^<FileModifyDate -d %%Y_%%m_%%d_%%H%%M%%%%-2c.%%%%e -r -P -overwrite_original -ext jpg -ext cr2 d:\testX >line2o.txt
exiftool -if "$DateTimeOriginal" -filename^<DateTimeOriginal -d %%Y_%%m_%%d_%%H%%M%%%%-2c.%%%%e -r -P -overwrite_original -ext jpg -ext cr2 d:\testX >line3o.txt
exiftool -if "not $DateTimeOriginal" -EXIF:DateTimeOriginal^<File:FileModifyDate -r -P -overwrite_original -ext jpg -ext cr2 d:\testX >line4o.txt

This is NOT elegant :), however it does this :- (for all files with ext JPG or CR2, in directory D:\testX and all its subdirectories)

line 1, Move current Filename into the IPTC field Caption-Abstract. This is for future reference, and is neat, because it appears in the Windows Explorer column 'Title' and can be viewed/added in the Details view of any Windows explorer page.
line 2, If there isnt a DateTimeOriginal (eg from scans or old jpgs) then set the Filename to be 2011_12_28_1706-cc.ext from the FileModifyDate (which is the best approximation to a useful date for the image)
line 3, If there IS a DateTimeOriginal, then set the Filename to be 2011_12_28_1706-cc.ext from theDateTimeOriginal (which is when the image was shot)
line 4, If there isnt a DateTimeOriginal, then set it to the FileDateModify (so now all my images have a 'Date Taken', visible in Windows explorer)

NB I output the results into a separate txt for for each line - eg line1o.txt

NB I haven't used the seconds part of the date for file naming, but i do have a 2 digit number if there are more than one image in a minute.

NB Now I'm hgetting the hang of this, I'm going to add lines to move the files into a 2011/2011_01_Jan type DIR structure!  :) (50Gb of images from about 10+ years)

Thanks to all on this forum and on the BRU forum for helping!

I do think that a really good GUI on front of this tool would get easy backing from VCs in SanFran becuase there is a HUGE need for this as the years go on, and Phil Harvey, you could make a lot of money getting a few grads to build this.

J

Phil Harvey

Well done.

Is the carat (^) used as an escape character in Windows?  I didn't know about this.

Just a quick tip:  You can copy multiple tags at once, so your first 3 commands can be replaced by this one:

exiftool -P -overwrite_original_in_place -r -ext cr2 -ext jpg -iptc:caption-abstract^<filename -filename^<FileModifyDate -filename^<DateTimeOriginal -d %%Y_%%m_%%d_%%H%%M%%%%-2c.%%%%e d:\testX >line1o.txt

In this command, FileName will be set to DateTimeOriginal if it exists, or FileModifyDate otherwise.  (The last valid assignment overrides earlier ones.)

Your 4th command still needs to be run separately.

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

jomk

Thanks Phil - you just made it elegant! :)

Yep, ^ is escape for windows.

btw, can I get hold of the month name for DIR naming?  eg 2011/1101_Jan     2011/1102_Feb  ?

Thanks, J

jomk

Doh!    http://www.exiftool.org/filename.html

%%b works perfectly  :)

%a   - abbreviated locale weekday name
%A   - full locale weekday name
%b   - abbreviated locale month name
%B   - full locale month name
%c   - preferred locale date/time representation
%d   - day of month (01-31)
%H   - hour on a 24-hour clock (00-23)
%I   - hour on a 12-hour clock (01-12)
%j   - day of year (001-366)
%m   - month number (01-12)
%M   - minute (00-59)
%p   - 'AM' or 'PM'
%S   - seconds (00-59)
%w   - weekday number (0-6)
%W   - week number of the year (00-53)
%x   - preferred locale date representation
%X   - preferred locale time representation
%y   - 2-digit year (00-99)
%Y   - 4-digit year (ie. 2006)
%Z   - time zone name
%%   - a literal '%' character