Replacing Keywords using the API

Started by dkdayton, December 27, 2010, 07:06:33 PM

Previous topic - Next topic

dkdayton

I am using perl and the api to replace tags on a large collection of photographs.  I can replace single value tags, but I can't figure out how to replace old tags in lists such as keywords.  The old items remain and the new items are appended on the end of the list.  Any suggestions?

Phil Harvey

I think that reading FAQ number 17 may help.  Let me know if you have any questions after reading this.

- 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 ($).

dkdayton

Thanks for the response. 

I read FAQ 17, but it discussed the issue issue in the context of the EXIFTOOL application.  I understand generally how list tags work, but I still don't know how to solve my specific problem.  I have some existing keyword tags in a large number of files that I want to delete using Perl and the EXIFTOOL library (not the application).  Is there a way to use the EXIF Library to delete all of the existing values for the keyword field, so that I can repopulate the field with only the values that I want to have there?

Thanks again.

Phil Harvey

Via the API, you do this to replace existing keywords:

$exifTool->SetNewValue(Keywords => 'word1');
$exifTool->SetNewValue(Keywords => 'word2');


or equivalently:

$exifTool->SetNewValue(Keywords => ['word1', 'word2']);

This is one of the examples in the SetNewValue() documentation.

Does this clear things up?

- 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 ($).

dkdayton

I am able to ADD keywords using that method.  The problem is that I don't seem to be able to remove existing keywords that I no longer want in the list.

An example might help.  Old keywords (oldword1 and oldword2 exist in the file) before I process it to add newword1 and newword2.  When I use the method you suggest, the list becomes: oldword1, oldword2, newword1, newword2.  I want it to be newword1, newword2.  How do I delete oldword1 and oldword2?

Deane

Phil Harvey

Hi Deane,

The method I suggested does delete oldword1 and oldword2.  You must specifically use the AddValue option if you want to preserve existing values.

If it doesn't work this way for you, there is something odd happening.  In this case a sample file and code snippet would be useful.

- 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 ($).