ExifTool Forum

ExifTool => Newbies => Topic started by: millerstevew on March 07, 2015, 11:48:20 AM

Title: Make part of a photo's directory name its IPTC Title
Post by: millerstevew on March 07, 2015, 11:48:20 AM
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!
Title: Re: Make part of a photo's directory name its IPTC Title
Post by: StarGeek on March 07, 2015, 12:24:38 PM
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

Title: Re: Make part of a photo's directory name its IPTC Title
Post by: millerstevew on March 08, 2015, 09:52:36 PM
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?
Title: Re: Make part of a photo's directory name its IPTC Title
Post by: StarGeek on March 08, 2015, 11:43:51 PM
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.