Copy tag only if it does not exist already

Started by alta, February 24, 2024, 11:36:47 AM

Previous topic - Next topic

alta

Hi, I'm using ExifTool to record the orginal filenames of images in the OriginalFilename tag and trying to come up with a command that doesn't change the value of the tag when it's run again on a file that was renamed. This example from the documentation seems perfect for that purpose:
exiftool -comment-= -comment='new comment' a.jpg
     Write  a  new  comment only if the image doesn't
     have one already.
However, when copying a tag instead of assigning a literal value, the tag gets overwritten if it already exists.

For example:
exiftool -OriginalFilename old.jpg
exiftool -OriginalFilename-= '-OriginalFilename<Filename' old.jpg
exiftool -OriginalFilename old.jpg
Original File Name              : old.jpgSo far, so good. But then:
mv old.jpg new.jpg
exiftool -OriginalFilename-= '-OriginalFilename<Filename' new.jpg
exiftool -OriginalFilename new.jpg
Original File Name              : new.jpg
Is this expected? What am I missing, and how can I keep the tag value unchanged once it exists?

StarGeek

Try the -wm (-writeMode) option, specifically -wm cg. That will "Create new tags" (c) and "Create new Groups as necessary" (g) but will not write to existing tags.
* 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).

alta

Thank you, StarGeek. That solved it and it'll be a very useful option to keep in mind.