ExifTool Forum

ExifTool => Newbies => Topic started by: jtboldon on October 29, 2021, 12:08:41 PM

Title: Flattening Tag Hierarchy
Post by: jtboldon on October 29, 2021, 12:08:41 PM
Hello,
I have been using Windows Live Photo Gallery for years but it is now time to move on. I have been using a keyword hierarchy which looks like this - Places/England/Dorset/Swanage/Swanage Railway and simpler ones like - Pub/Nelson  It did seem a good idea at the time???
Could someone please give me an idea as to a command for Exiftool which flattens my hierarchy such that a photo with those two hierarchic tags would now have separate keywords
Places, England, Dorset, Swanage, Swanage Railway, Pub, Nelson
Thanks in advance
jtb
Title: Re: Flattening Tag Hierarchy
Post by: StarGeek on October 29, 2021, 12:56:24 PM
First you need check to see where the keywords are held.  Run the command in FAQ #3 (https://exiftool.org/faq.html#Q3) to find them.  Odds are they are located in Subject and/or Keywords.

You could then run a command like this
exiftool -api "Filter=s(/)(, )g" -sep ", " -TagsFromFile @ -Subject -Keywords /path/to/files/

The -api Filter will convert all the slashes into (comma)(space).  The -sep option (https://exiftool.org/exiftool_pod.html#sep-STR--separator) then tells exiftool to separate lists type tags on (comma)(space).  The rest then copies the Subject and Keywords tags back into the file, now as separated keywords.

One thing to be careful of is if any of your keywords already included a comma, as it will separate on those as well.  For example, if you had the keyword of "Smith, John", this would make two keywords, "Smith" and "John".

This command creates backup files.  Add -Overwrite_Original (https://exiftool.org/exiftool_pod.html#overwrite_original) to suppress the creation of backup files.  Add -r (https://exiftool.org/exiftool_pod.html#r-.--recurse) to recurse into subdirectories.
Title: Re: Flattening Tag Hierarchy
Post by: jtboldon on October 31, 2021, 12:34:06 PM
Thank you so much!!!
Cheers,
John