Storing a tag value in a batch variable

Started by amadeogarcia, January 15, 2021, 02:58:18 PM

Previous topic - Next topic

amadeogarcia

Okey, I'm trying to do a simple script in batch (CMD, Windows) where I take a folder full of pictures (all with the same date and time) and start adding 3 or 5 minutes to each one so they don't appear to be taken at the exact same moment. So far it's fine, just a FOR with a counter and shifting minutes.

The thing is, now I have a folder with pictures from different days, and the way I designed the script, the counter starts in 0 and goes 5, 10, 15, 20, etc... I'd like to reset the counter whenever I change days, and in order to do that, I'd like to be able to store the DateTimeOriginal tag in a variable to then compare. Something like this:

SET previous_date=exiftool -DateTimeOriginal C:\MyImages\IMG_001.jpg
SET current_date=exiftool -DateTimeOriginal C:\MyImages\IMG_002.jpg
IF previous_date NEQ current_date (SET counter=0)


Well, as you probably already noticed, that pseudo-script does not work because ECHO %previous_date% will show exiftool -DateTimeOriginal C:\MyImages\IMG_001.jpg and not the actual value of the tag.

Is there a way to return the tag value so that I can store it (as a string, or whatever, I'll figure that later)?

amadeogarcia

First of all, I must apologize because turns out my issue was my lack of knowledge in Batch scripting rather in Exiftool scripting. That is, the solution is as simple as using a FOR /F loop. I will, however, leave this post in case anyone has a similar problem (although I don't think anyone will).

My solution:
FOR /F "tokens=*" %%D IN ('exiftool -p "$DateTimeOriginal" C:\MyImages\IMG_001.JPG') DO (SET current_date=%%D)

Now, ECHO %current_date% will display 2020:08:13 18:33:15, if that were the value of the Date/Time Original tag.

Phil Harvey

There are lots of posts in here about people trying to do the same thing.  You don't need a batch file.

Basically the command is (for 5 minute spacing):

exiftool "-datetimeoriginal+<0:${filesequence;$_*=5}" 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 ($).

StarGeek

That works for what they did in the first paragraph, but now they want a reset upon each change of day.
* 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).

rodanny

Quote from: amadeogarcia on January 15, 2021, 08:54:40 PMFirst of all, I must apologize because turns out my issue was my lack of knowledge in Batch scripting rather in Exiftool scripting. That is, the solution is as simple as using a FOR /F loop. I will, however, leave this post in case anyone has a similar problem (although I don't think anyone will).

My solution:
FOR /F "tokens=*" %%D IN ('exiftool -p "$DateTimeOriginal" C:\MyImages\IMG_001.JPG') DO (SET current_date=%%D)
Now, ECHO %current_date% will display 2020:08:13 18:33:15, if that were the value of the Date/Time Original tag.
Interesting,
tell me can read more tag and save each tag separately in this method?