Date from filename into AllDates - arbitrary date format

Started by Gepardienne, December 28, 2022, 04:35:07 PM

Previous topic - Next topic

Gepardienne

Hi,
I have a large number of files with wrong or missing metadata, but the filename contains the date info in various forms.
First question is, I have a number or WA images and videos containing date values as YYYYMMDD and then WAxxxx where xxxx is a running number. Using code I found in this forum I run into bad substitution error. What am I doing wrong?
% exiftool -P -a -s  ´-datetimeoriginal<${filename;s/WA.*//} 00:00:00´ xIMG-20210402-WA0023.jpg
zsh: bad substitution

Second question is, a lot of older files have date info in the form DD-MM-YYYY or YY-MM-DD and various other characters including numbers. How can I use the regex and globs to extract the date from these filename and put in a date tag?
I've tried several things like
exiftool '-CreateDate<${Filename;s/(\d\d\)-(\d\d)-(\d\d\d\d)/$3$2$1/}' . but it ends in error.

Is there an easy guide for regex, substitutions and modifications etc. that would explain how to use these commands?
I assume the easy way would be to put all files with a similar filename structure into a separate folder and make separate exiftool command to run for each folder.

I'm using MacOS 12 and exiftool 12.48

Thanks in advance!

StarGeek

Quote from: Gepardienne on December 28, 2022, 04:35:07 PM% exiftool -P -a -s  ´-datetimeoriginal<${filename;s/WA.*//} 00:00:00´ xIMG-20210402-WA0023.jpg
zsh: bad substitution

You're using angled/fancy quotes ´, not regular quotes '  Make sure you're not copy/pasting commands into something like a word processor or Google Docs.  Those will "help" you by correcting quotes into the fancy quotes which are appropriate for documents, but completely wrong for the command line.

QuoteSecond question is, a lot of older files have date info in the form DD-MM-YYYY or YY-MM-DD and various other characters including numbers. How can I use the regex and globs to extract the date from these filename and put in a date tag?
I've tried several things like
exiftool '-CreateDate<${Filename;s/(\d\d\)-(\d\d)-(\d\d\d\d)/$3$2$1/}' . but it ends in error.

You forgot the time component like was included in your first command.
exiftool '-CreateDate<${Filename;s/(\d\d\)-(\d\d)-(\d\d\d\d)/$3$2$1/} 00:00:00' .

QuoteIs there an easy guide for regex, substitutions and modifications etc. that would explain how to use these commands?

RegEx is complex.  There are lots of tutorials on the web, though.  Regular-Expressions.info is the one I learned on, though there may be better ones these days.  And sites like RegEx101.com, which allows you to test regular expressions and gives you a break down of each part, are also very helpful.

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

Gepardienne

Thanks @StarGeek for the very quick reply! I'll have to test this tomorrow. So I got close, but not quite there ;) I'll get back if I can't make it work. Have to take care with the quotes. I use the app Notes to copy-paste stuff and you're right about Notes making all kinds of substitutions.