Author Topic: Avoiding duplicate list items when combining XPKeywords and Subject tags  (Read 1710 times)

Hugh

  • Jr. Member
  • **
  • Posts: 20
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?

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3956
Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
« Reply #1 on: February 10, 2016, 04:39:57 PM »
See FAQ 17
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Hugh

  • Jr. Member
  • **
  • Posts: 20
Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
« Reply #2 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.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16879
    • ExifTool Home Page
Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
« Reply #3 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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Hugh

  • Jr. Member
  • **
  • Posts: 20
Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
« Reply #4 on: February 11, 2016, 07:25:39 AM »
Thanks. I missed the + .

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16879
    • ExifTool Home Page
Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
« Reply #5 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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Hugh

  • Jr. Member
  • **
  • Posts: 20
Re: Avoiding duplicate list items when combining XPKeywords and Subject tags
« Reply #6 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.