News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

get dates from '[YYYY-MM-DD] *.jpg' filename

Started by Joost, April 27, 2020, 02:51:22 AM

Previous topic - Next topic

Joost

Hi,

after spending numerous hours of googling, reading (mainly on this forum) and trying to work this out, I can't seem to be able.
I'd like to set 'all EXIF dates' based on filenames that have the date between square brackets and separated by dashes '[YYYY-MM-DD]', followed by either the extension '.jpg' or a foto description + extension '*.jpg' (where the description sometimes contains a number).

I've tried so many things that I can't really quote them all. One thing is clear though; below only works on a few files:
exiftool -Overwrite_Original '-AllDates<FileName' *.jpg

Any help would be much appreciated!
-Joost

Phil Harvey

Hi Joost,

The issue is that you also need to specify a time when writing a date/time tag.

You could do this

exiftool '-alldates<$filename 00:00:00' -ext jpg DIR

except that any numbers after the date in the file name would be interpreted as hours, minutes then seconds, which could result in an invalid date/time, or at the very least not all times would be zero.

However, using the advanced formatting feature you could reformat the filename to remove everything but the date, then add the time to that:

exiftool '-alldates<${filename;s/.*(\d{4}-\d{2}-\d{2}).*/$1/} 00:00:00' -ext jpg 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 ($).

Joost

Thank you very much Phil!
Super fast and nearly perfect.
2 questions:

  • Why would this logic not work with a file called "[1973-07-03] Oma's 66e verjaardag_1.jpg"? It struggles with 4 files, which only differ in the _# indicator at the end. It doesn't seem to struggle with files called "[1973-06-10] Pinksteren_1.jpg", where the same indexing is applied at the end.
  • Where can I maybe find documentation how this advanced formatting works? I can follow the "\d{#}-", but would like to understand the rest, so I can potentially fine-tune it if I ever run into different format filenames.

Thanks again!
-Joost

Phil Harvey

Hi Joost,

My second should work for the files you specified.  The first command, however, will take the "66" as the hours in the date/time for the first file you mentioned.  This will result in an illegal time, so it won't be set.

The advanced formatting is documented here, but for a complete syntax you would have to go to the Perl language documentation.

- 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 ($).

Joost

Hi Phil,

I guess there's something else with those files then, because exifTool is unable to convert the filename to a Date/Time:
Warning: No writable tags set from ./[1973-07-03] Oma's 66e verjaardag_4.jpg
Warning: No writable tags set from ./[1973-07-03] Oma's 66e verjaardag_2.jpg
Warning: No writable tags set from ./[1973-07-03] Oma's 66e verjaardag_3.jpg
Warning: No writable tags set from ./[1973-07-03] Oma's 66e verjaardag_1.jpg

I'll study some Perl syntax coding then...

Thanks for all the help! Awesome tool you've built!
-Joost

Phil Harvey

That's odd.  It worked for me when I tried it with this file name.  If you are on Windows, use double quotes.

If that still doesn't work, try adding -v3 to the command to get more details.

- 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 ($).

Joost

Must've been file system related, as when I try it now, it works fine.

Thanks again!
-Joost