Parse year from basename

Started by PlasticArmyGuy, April 20, 2025, 12:58:03 PM

Previous topic - Next topic

PlasticArmyGuy

I have multiple scanned photos with a year in the filename.  For example, a file may be named Tom_graduation_1952_photo.jpg or Mustang_Sally_1968.jpg.  The year can appear anywhere within the name.

I have been trying without success to parse the four digits and insert that into the subject tag. 

Can this be done and if so, how?

Appreciate any assistance.

StarGeek

Try
exiftool "-Subject+<${Filename;m/(\d{4})/;$_=$1}" /path/to/files/

This command will grab four consecutive numbers and add that to the XMP-dc:Subject, which is used to hold keywords.
"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

PlasticArmyGuy

Thank you.  That works well.

Would it be possible to modify this to skip files that do not have a date in the name?

StarGeek

Try
exiftool -if "$filename=~m/(\d{4})/" "-Subject+<${Filename;m/(\d{4})/;$_=$1}" /path/to/files/
"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

PlasticArmyGuy