Missing something obvious in setting create date

Started by zathras, June 30, 2024, 05:05:04 PM

Previous topic - Next topic

zathras

I've got exiftool 12.87 on Windows 11 (the direct exe install that doesn't require PERL separately) and I'm trying to set the create date based on the content of the filename.  I found several great examples that suggested this type of syntax:
   
    exiftool.exe "-createdate<${filename;$_=/(\d+)_(\d+)_B/ ? $1\:$2 : undef}:01 00:00:00" .

(given my file names are formatted as 2000_12_B001_0001.png, (year, month, Batch, item-in-batch))

That went badly on date-formatting so I started testing with simpler attempts, to see what was being generated.  I started setting the imagedescription tag.  I tried all sorts of combinations, getting simpler and simpler, but it SEEMS like the "filename" tag isn't getting translated within the curly brackets. I say "Seems" because I know I must be missing something obvious, but I've scoured the forums and tried everything I could find.

    exiftool.exe "-imagedescription=${filename;} 0x:00:00" 1990_08_B096_0001.png

This sets the imagedescription to "0x:00:00". I've tried it with the < instead of =, camelbacking "filename", Leaving off the static "0x.." part, and several other things like passing it through a "s/_/q/g" just to see if it had to have some processing.  Nothing works.

note: exiftool.exe "-imagedecription<filename"  does work but it doesn't get me closer to being able to do the parsing that would require the ${} syntax.

I know the regex above will need some tweaking to get it right, I'm good with that. But simply getting the tags to resolve within the ${} seems to be my biggest hurdle.

Any assistance would be greatly appreciated.  Thanks in advance.


StarGeek

Quote from: zathras on June 30, 2024, 05:05:04 PMbut it SEEMS like the "filename" tag isn't getting translated within the curly brackets.

It isn't

tl;dr Use CMD, not PowerShell.  Longer version here

The colon either need to be quoted and concatenated (Perl dot . operator) or it can be completely removed. The reason for the latter is FAQ #5, paragraph starting "Having said this..."

exiftool.exe "-createdate<${filename;$_=/(\d+)_(\d+)_B/ ? $1.':'.$2 : undef}:01 00:00:00" .
or
exiftool.exe "-createdate<${filename;$_=/(\d+)_(\d+)_B/ ? $1$2 : undef}:01 00:00:00" .
which, because of FAQ #5, would be the same as
exiftool.exe "-createdate<${filename;$_=/(\d+)_(\d+)_B/ ? $1$2 : undef}01 000000" .


* 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).

zathras

That you're right goes without saying. Thanks very much for the CMD/Powershell callout, as well as the tweaks to the regex.   I gave it a run but it's unhappy for a different reason now.  I'm getting

Setting new values from 1990_08_B096_0001.png
Writing XMP-tiff:ImageDescription if tag exists
Writing IFD0:ImageDescription
Warning: syntax error for 'filename' - 1990_08_B096_0001.png


Which I understand to mean that the regex didn't match correctly in the string, so it's a fail. 

I'm using your last example:
exiftool.exe "-createdate<${filename;$_=/(\d+)_(\d+)_B/ ? $1$2 : undef}01 000000" 1990_08_B096_0001.png

Which is right, of course, and works perfectly well in Regex101 to identify 1990 and 08.  I've tried several different iterations to no avail.  I hate to come back to the well so quickly when it's probably another simple "in windows you need to stand on your left foot while pressing enter" sorta thing, but here I humbly am, nonetheless.

Any ideas?

StarGeek

#3
Ooops, sorry, didn't follow my own advice.  Forgot the dot to concatenate

Examples. The first command, then clear the create date, then the second command
C:\>exiftool -P -overwrite_original "-createdate<${filename;$_=/(\d+)_(\d+)_B/ ? $1.':'.$2 : undef}:01 00:00:00" Y:\!temp\x\y\1990_08_B096_0001.png
    1 image files updated

C:\>exiftool -G1 -a -s -createdate Y:\!temp\x\y\1990_08_B096_0001.png
[PNG]           CreateDate                      : 1990:08:01 00:00:00

C:\>exiftool -P -overwrite_original -createdate= Y:\!temp\x\y\1990_08_B096_0001.png
    1 image files updated

C:\>exiftool -P -overwrite_original "-createdate<${filename;$_=/(\d+)_(\d+)_B/ ? $1.$2 : undef}01 000000" Y:\!temp\x\y\1990_08_B096_0001.png
    1 image files updated

C:\>exiftool -G1 -a -s -createdate Y:\!temp\x\y\1990_08_B096_0001.png
[PNG]           CreateDate                      : 1990:08:01 00:00:00


Take note though, this is setting the PNG:CreateDate tag, which may not be what you want, depending upon what programs you are using will read.  You may instead want to use EXIF:CreateDate.  If you want it to show up as "Date Taken" under the Windows Properties, you would want to use CreationTime.
* 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).

zathras

Outstanding.  That did the trick very nicely.  Thanks very much for all your help, both on this issue and your dedication to the tool and across this forum for years.

Regards,

Zathras