Settings Old JPG EXIF data from file

Started by Madbyte, February 01, 2022, 06:19:56 PM

Previous topic - Next topic

Madbyte

Hi,

I found this excellent tool and it is exactly what I was looking for, but I'm getting some trouble to make it work. I need to set EXIF data from old files named like this: 02-06-09 001.jpg where 02:DD 06:MM 09:YY. I was reading the forum, found some clues, but I can't found information how filename patterns works.

First I set DateTimeOriginal using this command:
exiftool "-DateCreated = "2009 01 01 00:00:00" *

Then from other post (https://exiftool.org/forum/index.php?topic=8456.0) with similar to my date pattern:
exiftool "-AllDates<${filename;s/.*@(\d\d)-(\d\d)-(\d{4})(.*)/$3 $1 $2 $4/}" FileOrDir

I changed to:
exiftool "-DateTimeOriginal<${filename;s/.*@(\d\d)-(\d\d)-(\d{4})(.*)/$3 $1 $2 $4/}" *

I can't understand what means all characters following filename: ;s/.*@(\d\d)-(\d\d)-(\d{4})(.*)/$3 $1 $2 $4/ (where I can find information about this?)

And running last command gives me:
Warning: No writable tags set from somefile

Any help? Thanks









StarGeek

Quote from: Madbyte on February 01, 2022, 06:19:56 PM
First I set DateTimeOriginal using this command:
exiftool "-DateCreated = "2009 01 01 00:00:00" *

You have an extra quote here.  You can either put quotes around the whole thing
"-DateTimeOriginal=2009 01 01 00:00:00"
or around just the part that has the space
-DateTimeOriginal="2009 01 01 00:00:00"

When you are copying one tag to another using the less than sign, you need to put the quotes around the whole thing
"-DateTimeOriginal<Filename"

I would also suggest using DateTimeOriginal and/or CreateDate rather than DateCreated.  Or even better is AllDates which will fill both at the same time.  The DateCreated tag is an older IPTC Legacy tag this isn't used very much.  It only holds the date portion and the time portion is held in a separate tag, which can be inconvenient.

QuoteI can't understand what means all characters following filename: ;s/.*@(\d\d)-(\d\d)-(\d{4})(.*)/$3 $1 $2 $4/ (where I can find information about this?)

That is a Perl Regular Expression (RegEx).  That's a whole topic on it's own and is best learned on websites dedicated to teaching about it such as regular-expressions.info.

The important parts of that regex is the parentheses, which capture matches and fill the $1/$2/$3 variables, and the \d, which stands for a single numeric character.

In your case, though, I would suggest using a match m/MATCH/ operations rather than the substitution s/MATCH/REPLACE/ operation.

The command I would suggest would be
exiftool "-AllDates<${Filename;m/(\d\d)-(\d\d)-(\d\d)/;$_='20'.$3.$2.$1} 00:00:00" /path/to/files/

What this does is match a pattern of 2NumbersDash2NumbersDash2Numbers, capturing the numbers and ignores the rest of the filename, because you don't want any of the trailing numbers to be used as a time stamp.  It then replaces the value of Filename with those numbers in reverse order and prefixed by 20, so the result is 20YYMMDD.  Finally, outside of that operation, a default time of midnight 00:00:00 is added to the end.
* 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).

Madbyte

Hi,

Thanks!! That suggested command did the job!! (Need to see that page to understand Regular Expressions in Perl)