delete tag in img-file if same tag in xmp is empty or missing

Started by snahl, February 22, 2013, 09:31:12 PM

Previous topic - Next topic

snahl

Hi,

When rewriting XMP data to NEF files, I am trying to remove the existing tag 'xmp:label' in the NEF files on the condition that the same tag is empty or not existing in the corresponding xmp file.

Having trouble to figure this one out. Therefore I tried with the code below.
But that code removes 'xmp:Label' in the XMP file (on the condition the content is not equal empty) instead of in the NEF file. Of course that's not what I anticipate.

exiftool -v3 -P -tagsfromfile %d%f.xmp -XMP:all "-xmp:Label=" -if "$XMP-xmp:Label ne ''" "d:\IMAGES\2013\02-21 Ice Lanterns\series-of-7\s7-000\NK238838.NEF" "d:\IMAGES\2013\02-21 Ice Lanterns\series-of-5\s5-006\NK238839.NEF"

I'd like it to remove the 'xmp:Label' in the NEF files instead, based on the content condition of the corresponding tag in the XMP file.
The wrong example above list only 2 files to be processed.
Finally, the idea is to have many more NEF files being processed that way.
The folder structure varies and both the NEFs and XMPs are always paired in the same folder.

Hope I explained it clearly.
I'd assume that this is possible, but I don't know how?
Advice and hints are appreciated, thanks.

----------------------------------------------
Edit 23.Feb.2013: trial-and-error to figure out how to meet the condition:

The command below works on the condition [(ne '') not equal empty => true] because the tag xmp:Label does NOT exist in the xmp-file, therefore the condition [ne ''] returns true and the tag xmp:label is removed from the NEF file.

exiftool -P -if "$XMP-xmp:Label ne ''" "d:\IMAGES\2013\Test2\02-21 Ice Lanterns\series-of-7\s7-000\NK238838.xmp" -XMP-xmp:Label=  "d:\IMAGES\2013\Test2\02-21 Ice Lanterns\series-of-7\s7-000\NK238838.NEF"

So that's a first step, except that the content of the condition can be anything with the same result.
Sorry, but couldn't find a suitable operator for '-if'.
Is it possible to check whether a xmp-tag exists or not? In case the tag xmp:Label exists in the xmp-file, the condition is NOT met and the command should copy that tag as part of the -tagsfromfile %d%f.xmp -XMP:all in the command.

Alternatively, would a table query work. Allowed values for xmp:Label are: valLabels = ("Select", "Second", "Approved", "Review", "To Do")?
If so, how?
Dig-IT-all

Phil Harvey

Unfortunately the -if condition acts on the target file only, so this won't work the way you want.

Someone else tried to do this once, but I couldn't think of a search query that was unique enough to be able to find the old thread in the forum.

Anyway, this can be done in 2 steps:

1) Get a list of all XMP sidecar files in directory DIR that do not contain a label:

exiftool -if "not $xmp-xmp:label" -srcfile %d%f.xmp -p "$directory/$filename" -ext nef DIR > files.txt

2) Use this list to process the corresponding NEF files to remove their label:

exiftool -srcfile %d%f.nef -xmp-xmp:label= -@ files.txt

Here I have used the somewhat confusing -srcfile option to process the related files.  The "not" condition will be true if the label is missing, empty (""), or zero ("0").

- 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

I have added a note about this to the documentation, and this will appear in the next release:

            4) The condition may only test tags from the file being processed.
            To process one file based on tags from another, two steps are
            required.  For example, to process XMP sidecar files in directory
            "DIR" based on tags from the associated NEF:

             a) exiftool -if EXPR -p '$directory/$filename' -ext nef DIR > nef.txt

             b) exiftool -@ nef.txt -srcfile %d%f.xmp ...


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

snahl

Dig-IT-all

snahl

Dig-IT-all

snahl

...one more minor thing:

When I use the -P option (-preserve) the date/time of NEF files is changed to current system date/time.

exiftool -P -srcfile %d%f.nef -xmp-xmp:label= -@ files.txt

I understand that Windows shows the Date modified and in Properties the Date created remains unchanged.
Of course the NEF got modified on purpose with this command so it makes sense that the Date modified changes.

But then how can I make use of the -P option?
Isn't it here to preserve that modification date?

I must have missed something! But what?

Environment is Windows7-64.
Dig-IT-all

Phil Harvey

I don't understand this.  I'm afraid you're going to have to track this one down yourself.  My hope is that something else touched the file and that you're fooling yourself somehow.

What happens if you run these 3 commands?:

1) exiftool -filemodifydate test.jpg

2) exiftool -P -xmp-xmp:label=test test.jpg

3) exiftool -filemodifydate test.jpg

... and does this FileModifyDate agree with whatever system date you're using?

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

snahl

...same here, I don't understand.
You're right that somehow I must be fooling myself. So I dig further to find that 'thing' touching the files.

The results are correct as expected:

exiftool -filemodifydate NK237112-B.NEF
File Modification Date/Time     : 2013:03:09 01:59:59+01:00

exiftool -P -xmp-xmp:label=test NK237112-B.NEF
    1 image files updated

exiftool -filemodifydate NK237112-B.NEF
File Modification Date/Time     : 2013:03:09 01:59:59+01:00

and in Windows7-64:

dir NK237112-B.NEF
09.03.2013  01:59        13'044'814 NK237112-B.NEF
Dig-IT-all