Avoiding duplicate list items when combining XPKeywords and Subject tags

Started by Hugh, February 10, 2016, 04:21:13 PM

Previous topic - Next topic

Hugh

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

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Hugh

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

Quote from: Hugh on February 11, 2016, 04:23:25 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/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).


Phil Harvey

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/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Hugh

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.