ExifTool Forum

ExifTool => Newbies => Topic started by: Hugh on February 10, 2016, 04:21:13 PM

Title: Avoiding duplicate list items when combining XPKeywords and Subject tags
Post by: Hugh on February 10, 2016, 04:21:13 PM
I am trying to combine the contents of IDF0:XPKeywords and XMP:Subject and write the combined list into XMP:Subject.

The following code seems to do it, except that where a keyword is in both XPKeywords and Subject it is duplicated in the output:
cd "\My Progs\ExifTool\Before"
"C:\My Progs\ExifTool\exiftool.exe" -k -r -sep "; " -addtagsFromFile @ "-Subject<Subject" "-Subject<XPKeywords" * -o "C:/My Progs/ExifTool/After/%%d/"


Is it possible to amend the code to avoid duplicates?
Title: Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
Post by: StarGeek on February 10, 2016, 04:39:57 PM
See FAQ 17 (http://www.exiftool.org/faq.html#Q17). 
Title: Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
Post by: Hugh on February 11, 2016, 04:23:25 AM
Thanks for your reply.

My problem is that some of my photo files have some keywords in Subject that are not in XPKeywords.

If I understand it correctly, FAQ 17 says that "exiftool -Subject<Subject" "-Subject<XPKeywords" avoids duplication by simply overwriting Subject with the contents of XPKeywords. That is what happened when I tried it (before I read about -addtagsfromfile). However, this means that keywords that are in Subject but not in XPKeywords are lost.
Title: Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
Post by: Phil Harvey on February 11, 2016, 07:19:55 AM
If I understand it correctly, FAQ 17 says that "exiftool -Subject<Subject" "-Subject<XPKeywords" avoids duplication by simply overwriting Subject with the contents of XPKeywords.

The above command is the same as exiftool "-Subject<XPKeywords"

You want this to keep the original items and add new ones avoiding duplicates:

exiftool -addtagsfromfile @ "-subject-<xpkeywords" "-subject+<xpkeywords" -sep "; " DIR

- Phil
Title: Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
Post by: Hugh on February 11, 2016, 07:25:39 AM
Thanks. I missed the + .
Title: Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
Post by: Phil Harvey on February 11, 2016, 07:50:49 AM
The "+" makes no difference in this command.  It is assumed since there was a "-" in another copy (and -addTagsFromFile was used, so the earlier copy wasn't overridden).

- Phil
Title: Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
Post by: Hugh on February 11, 2016, 08:01:15 AM
I've just seen your reply to my last post.

Yes, I realised that I had also missed the -< !!!

I now understand the logic ... remove from Subject the tags that are duplicated then add to Subject all the tags that are in XPKeywords.

My test file looks good. I'll now try it out on a whole month's worth of photos.

Thanks again.