Extract Date from Filename

Started by jj168, April 30, 2024, 11:35:15 AM

Previous topic - Next topic

jj168

Hi,

I am trying to extract the date from the filename and update the dates in the meta of jpgs. I don't really care about the time. I'm using MacOS 14.

My filenames are in the form of:

2024-03-01-in.jpg
2024-03-01-out.jpg

I've tried many commands from this forum but haven't found a working solution.

In particular, I've tried these 2 commands:

exiftool "-AllDates<filename" 2024-03-01-in.jpg
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in ExifIFD:DateTimeOriginal (PrintConvInv) - 2024-03-01-in.jpg
    0 image files updated
    1 image files unchanged

exiftool "-AllDates<${filename;s/in/000000/}" 2024-03-01-in.jpg
zsh: bad substitution

Can you please help?

Thank you very much.

StarGeek

On Mac/Linux, using single quotes instead of double quotes.  Double quotes around a $ causes the shell to interpret it as a shell variable instead of an exiftool one.

The three tags that make up the AllDates shortcut require date and time, 14 numbers.  That is also why the first command fails.  You can use a substitution like in your second command as long as the quotes are correct, but as long as there are no other numbers, like a copy number, you can just append the 00 time
exiftool "-AllDates<$filename 00:00:00" /path/to/files/
* 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).

jj168

Thank you! Now it works perfectly

SybrBlue

Can you expand JJ?  Which code worked?  I suppose I will try on my own, but can you use this to process an entire directory?

StarGeek

Quote from: SybrBlue on May 01, 2024, 12:37:37 PMCan you expand JJ?  Which code worked?  I suppose I will try on my own, but can you use this to process an entire directory?

Yes.  Where I put /path/to/files/ you can put any number of directory paths and/or individual filenames.  Add the -r (-recurse) option to recurse into subdirectories.
* 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).