Make part of a photo's directory name its IPTC Title

Started by millerstevew, March 07, 2015, 11:48:20 AM

Previous topic - Next topic

millerstevew

I'm attempting to title my photos with information from part of their parent directories.

All of my photos have a parent directory in the following format: "YYYY.MM.DD - Event Description" or "YYYY.MM.DD - YYYY.MM.DD - Multi-Day Event Description".

I would like to copy just the event description from the parent directory to the IPTC Title field. I know this can be accomplished using a regular expression, but I'm at a loss where to begin, especially since some folders have one date, i.e. the date of the event, and some folders have two dates, a start date and an end date. Parent folders only contain date and description information, so subtracting the date information should yield the event description.

Ideally, I would have a terminal command that could run recursively on my folder of 2014 events. Could you kindly help me figure out what the terminal command would be?

Thanks!

StarGeek

Assuming that's the exact format, this is what I came up with

ExifTool -r "-title<${directory;s/.*\d{4}\.\d\d\.\d\d - (?!\d{4}\.\d\d\.\d\d)(.*)(?:$)/$1/}" FILE/DIR

Example output:c:\Server\My_stuff>exiftool -title -r X:\!temp\y
======== X:/!temp/y/2014.04.18 - Event Description/Test.jpg
======== X:/!temp/y/2014.07.24 - 2014.07.27 - Multi-Day Event Description/Test.jpg
    3 directories scanned
    2 image files read

c:\Server\My_stuff>exiftool -overwrite_original -r "-title<${directory;s/.*\d{4}\.\d\d\.\d\d - (?!\d{4}\.\d\d\.\d\d)(.*)(?:$)/$1/}" X:\!temp\y
    3 directories scanned
    2 image files updated

c:\Server\My_stuff>exiftool -title -r X:\!temp\y
======== X:/!temp/y/2014.04.18 - Event Description/Test.jpg
Title                           : Event Description
======== X:/!temp/y/2014.07.24 - 2014.07.27 - Multi-Day Event Description/Test.jpg
Title                           : Multi-Day Event Description
    3 directories scanned
    2 image files read


Points of failure on this would be if the Event description is not the very last directory in the path, if there is a extra date in the event description part (e.g. 2014.07.24 - 2014.07.27 - Multi-Day Event Day 2014.07.25 Description), or if there is multiple spaces around the dashes (easy fix on that, though).

I would test it out with this command, which would list the text which would end up in the Title
exiftool -r -p "${directory;s/.*\d{4}\.\d\d\.\d\d - (?!\d{4}\.\d\d\.\d\d)(.*)(?:$)/$1/}" DIR

"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

millerstevew

Thanks for the help.

The command is working properly except in instances when there are two dates in the parent folder, e.g. "2003.07.05 - 07.13.2003 - Summer Vacation". In this case, the command only strips the first date and not the second. In this case, the command:

ExifTool -r "-title<${directory;s/.*\d{4}\.\d\d\.\d\d - (?!\d{4}\.\d\d\.\d\d)(.*)(?:$)/$1/}" FILE/DIR

yields the title: 07.13.2003 - Summer Vacation
and not: Summer Vacation

How should we modify the command to make it include parent folders with two sets of dates?

StarGeek

That's because you originally said your pattern was "YYYY.MM.DD - YYYY.MM.DD - Multi-Day Event Description".   Your Summer Vacation event is "YYYY.MM.DD - MM.DD.YYYY".  If this is your actual pattern, use:

ExifTool -r "-title<${directory;s/.*\d{4}\.\d\d\.\d\d - (?!\d\d\.\d\d\.\d{4})(.*)(?:$)/$1/}" FILE/DIR

If you have mixed patterns, that will take something more complicated.
"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