Writing Date Tags Using Data From Filenames

Started by klind, September 08, 2020, 06:26:51 PM

Previous topic - Next topic

klind

Given jpg files with the following example file names in <dir> - (Note that I use dot or period for <dir> after CD to the particular directory:

1968-06-05 ~xxxxxxxxxxxxxxxx ~001.jpg
2002-06-05 ~xxxxxxxxxxxxxxxx ~002.jpg
2003-05-05 ~xxxxxxxxxxx844xx ~003.jpg
2004-06-06 ~xxxxxxxxxxxxxxxx ~079.jpg

Using the following command individually works as expected on the first two files:

exiftool -'FileCreateDate<$filename 111111' -'AllDates<$filename 111111' -execute -if '$Filename lt "1972"' -FileCreateDate=19720101000000 -AllDates=19720101000000 -common_args -overwrite_original_in_place -P <dir>

However, the other two files do not get changed. I have determined that the error is caused by additional numbers and/or numerals higher than six within the file name.

How can I tell Exiftool to only consider the date at the beginning of the filename?

Ken Lind

StarGeek

You could use something like this
'-AllDates<${filename;m/^([\d-]*)/$_=$1} 111111'

This will match any digits or hyphens at the start of the file name and drop anything after that.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

klind

Ken Lind