I made photos on several cameras, all my photos have got names like: "2016.04.25_13.55.46_0_HDR-XR500VE.jpg" or "2016.04.25_15.56.57_0_Canon PowerShot G11.jpg"
I want to correct time data on one of them (having HDR in name) and use this corrected information to change file name. I don't need backup.
I do this job in 4 steps:
1. I use CreateDate as base for modification - so I assign CreateDate to DateTimeOriginal
2. I modify DateTimeOriginal
3. each photo should get new name using this new time stamp
4. also file time stamp has to be modified accordingly to the new time
My batch works but it takes a lot of time since each photo has be evaluated 4 times. I wonder if there is some optimization I can use here?
These are lines from my batch:
@echo off
call :RunAnalyse ".\*HDR*.jpg"
goto:EOF
:RunAnalyse
"exiftool" -P -progress -r -wm wc -i SYMLINKS -overwrite_original_in_place "-DateTimeOriginal<CreateDate" %1
"exiftool" -P -progress -r -wm wc -i SYMLINKS -overwrite_original_in_place "-DateTimeOriginal+=1:00" %1
"exiftool" -P -progress -r -i SYMLINKS -overwrite_original_in_place "-filename<${DateTimeOriginal}%%+.1c_${model;}.%%e" -d %%Y.%%m.%%d_%%H.%%M.%%S %1
"exiftool" "-FileModifyDate<DateTimeOriginal" %1
goto:EOF
First, just a comment about your subroutine call. You should probably use "exit /b" to return from your subroutine.
As for your question, this can all be done in a single command:
"exiftool" -P -progress -r -i SYMLINKS -overwrite_original_in_place -globalTimeShift +1 "-datetimeoriginal<createdate#" "-FileModifyDate<createdate#" "-filename<${createdate}%%+.1c_${model;}.%%e" -d %%Y.%%m.%%d_%%H.%%M.%%S %1
- Phil
Thanks Phil,
I understand that all params are evaluated from left to right, because time modification should be dome first and it is at the beginning of the batch, doesn't it?
I don't want to go for this option:
-globalTimeShift +1
the only time I want to modify is DateTimeOriginal, this would guaranty that I'd have reference value I can use for any further correction.
For example if my photo would be modified by accident (within some deep subfolder) I still would have original data to work with, to redo my modification.
I executed this code and found not much changes, take a look.
Before correction:
2016-03-27 09:54 2016-03-27_09.54.34_0_HDR-XR500VE.jpg
2016-03-27 09:58 2016-03-27_09.58.30_0_HDR-XR500VE.jpg
2016-03-27 20:20 2016-03-27_20.20.37_0_HDR-XR500VE.jpg
After correction (used -globalTimeShift +1:30):
2016-03-27 09:54 2016.03.27_11.24.34_0_HDR-XR500VE.jpg
2016-03-27 09:58 2016.03.27_11.28.30_0_HDR-XR500VE.jpg
2016-03-27 20:20 2016.03.27_21.50.37_0_HDR-XR500VE.jpg
EXIF data after correction:
DateTime - 2016:03:27 09:54:34
DateTimeOriginal - 2016:03:27 09:54:34
So your batch line just change name correctly, EXIF data is not changed, file time stamp is not modified.
Need to ask for the another tip.
Ah. My mistake was that the GlobalTimeShift applies only to the formatted date/time value:
-globalTimeShift SHIFT
Shift all formatted date/time values by the specified amount when
reading. Does not apply to unformatted (-n) output.
I had added the "#" to use the unformatted value, but it wasn't necessary since your formatting is valid format for writing. Try this instead:
"exiftool" -P -progress -r -i SYMLINKS -overwrite_original_in_place -globalTimeShift +1 "-datetimeoriginal<createdate" "-FileModifyDate<createdate" "-filename<${createdate}%%+.1c_${model;}.%%e" -d %%Y.%%m.%%d_%%H.%%M.%%S %1
- Phil
Yes, this line does exactly what I need :)
I don't understand how -globalTimeShift could change only the DateTimeOriginal and not CreateDate but result is ok.
Many thanks !!! You've saved plenty of my time.
The -globalTimeShift option only affects the values of date/time tags when reading. It doesn't cause anything to be written.
In your case you are reading CreateDate, shifting it with the -globalTimeShift option, and writing the result to DateTimeOriginal, FileModifyDate and FileName through the arguments specified on the command line.
- Phil
Ok, I got it. So -globalTimeShift option change data for all time stamps but only within kind of internal buffer of exiftool, there is no change on photo file until explicit stated.
Good to understand this function. Thanks for clarifications.
This is my batch file (if anyone interested):
@echo off
call :RunAnalyse "*SON*.jpg" +1:00
call :RunAnalyse "*CAN*.jpg" -1:00
call :RunAnalyse "*LUM*.jpg" +1:00
call :RunAnalyse "*GX8*.jpg" +1:00
goto:EOF
:RunAnalyse
exiftool -P -progress -r -i SYMLINKS -overwrite_original_in_place -globalTimeShift %2 "-datetimeoriginal<createdate" "-FileModifyDate<createdate" "-filename<${createdate}%%+.1c_${model;}.%%e" -d %%Y.%%m.%%d_%%H.%%M.%%S %1
One question I have is how to make ExifTool to browse subdirectories? I thought -recurse option would do the job but I'm wrong. For each folder I can modify files from this single folder and not from any subdir.
Is any other switch to search for defined files (like "*LUM*.jpg") within current folder and all subdirs ? Actually recurse is valid only when applied with folder name.
Is batch file the only option to handle this task?
The -r option is only meaningful if you specify a directory name. So to use this you could do something like this:
exiftool -r -ext jpg -if "$filename=~/SON/i" DIR
- Phil
Your answers are either fast and good :)
This is final batch to handle my task:
@echo off
call :RunAnalyse "HDR" "-1:00"
call :RunAnalyse "G11" "+1:00"
call :RunAnalyse "FT5" "-1:00"
call :RunAnalyse "GX8" "+1:00"
goto:EOF
:RunAnalyse
exiftool -r -ext jpg -if "$filename=~/%1/i" -P -progress -i SYMLINKS -overwrite_original_in_place -globalTimeShift %2 "-datetimeoriginal<createdate" "-FileModifyDate<createdate" "-filename<${createdate}%%+.1c_${model;}.%%e" -d %%Y.%%m.%%d_%%H.%%M.%%S .
Fast and efficient.
Thanks Phil again
Actually, could be more efficient because the -if condition requires processing of all JPG files, so metadata is extracted from all files 4 times with your script, but I can't see any alternative other than doing the file search yourself again.
- Phil
I did comparison between scripts:
@echo off
echo ================ %Date% %Time% >> operation.log
call :Search HDR "-1:00"
call :Search G11 "+1:00"
call :Search FT5 "-1:00"
call :Search GX8 "+1:00"
echo ================ %Date% %Time% >>operation.log
goto:EOF
:Search
for /f "tokens=*" %%A in ('dir /A:d /b /on /s *') do (call :RunAnalyse "%%A\*%1*.jpg" %2)
goto:EOF
:RunAnalyse
echo Files: %1
exiftool -progress -overwrite_original_in_place -globalTimeShift %2 "-datetimeoriginal<createdate" "-FileModifyDate<createdate" "-filename<${createdate}%%+.1c_${model;}.%%e" -d %%Y.%%m.%%d_%%H.%%M.%%S %1
and:
@echo off
echo ================ %Date% %Time% >> operation.log
call :RunAnalyse HDR "-1:00"
call :RunAnalyse G11 "+1:00"
call :RunAnalyse FT5 "-1:00"
call :RunAnalyse GX8 "+1:00"
echo ================ %Date% %Time% >> operation.log
goto:EOF
:RunAnalyse
exiftool" -r -ext jpg -if "$filename=~/%1/i" -P -progress -i SYMLINKS -overwrite_original_in_place -globalTimeShift %2 "-datetimeoriginal<createdate" "-FileModifyDate<createdate" "-filename<${createdate}%%+.1c_${model;}.%%e" -d %%Y.%%m.%%d_%%H.%%M.%%S .
'Operation.log' file presents for the first:
================ 2016-06-21 7:28:14,06
================ 2016-06-21 7:28:49,43
and the second:
================ 2016-06-21 7:29:31,62
================ 2016-06-21 7:29:39,76
Using just exiftool is much more efficient, 8 seconds against 35 measured with batch script with "FOR" command.
Interesting. I wouldn't have predicted this.
The first bat is looping and running ExifTool on individual files, so there's the additional startup time for each instance of Exiftool.
Quote from: StarGeek on June 21, 2016, 11:43:25 AM
The first bat is looping and running ExifTool on individual files, so there's the additional startup time for each instance of Exiftool.
Ah, right.
- Phil
I've met another problem, this my command line:
exiftool -ext jpg -P -m -F -wm wcg -progress -overwrite_original_in_place "-IFD0:ModifyDate<DateTimeOriginal" "-ExifIFD:CreateDate<DateTimeOriginal" "-FileModifyDate<DateTimeOriginal" "-FileName<${DateTimeOriginal}%%+.1c_${model;tr/ /_/}.%%e" -d "%%Y_%%m_%%d/%%Y.%%m.%%d_%%H.%%M.%%S" .
doesn't change time stamp?!
When revert to
exiftool -ext jpg -P -m -F -wm wcg -progress -overwrite_original_in_place "-IFD0:ModifyDate<DateTimeOriginal" "-ExifIFD:CreateDate<DateTimeOriginal" "-FileModifyDate<DateTimeOriginal" "-FileName<${DateTimeOriginal}%%+.1c_${model;tr/ /_/}.%%e" -d "%%Y.%%m.%%d_%%H.%%M.%%S" .
(no shift to subfolder) it works as expected.
I need to split task into 2 lines:
exiftool -ext jpg -m -F -wm wcg -progress -overwrite_original_in_place "-IFD0:ModifyDate<DateTimeOriginal" "-FileName<${DateTimeOriginal}%%+.1c_${model;tr/ /_/}.%%e" -d "%%Y.%%m.%%d\%%Y.%%m.%%d_%%H.%%M.%%S" .
exiftool -ext jpg -progress -r "-FileModifyDate<CreateDate" .
I wonder whether there is some way to bypass this issue?
Yes. Your date-time formatting is messing up the copies to the date/time tags. Add a "#" to disable the formatting when doing these copies: eg) "-IFD0:ModifyDate<DateTimeOriginal#"
- Phil
You are absolutely right.
Thanks Phil for your brillant support :D