ExifTool Forum

ExifTool => Newbies => Topic started by: alta on February 24, 2024, 11:36:47 AM

Title: Copy tag only if it does not exist already
Post by: alta on February 24, 2024, 11:36:47 AM
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?
Title: Re: Copy tag only if it does not exist already
Post by: StarGeek on February 24, 2024, 11:52:07 AM
Try the -wm (-writeMode) option (https://exiftool.org/exiftool_pod.html#wm-MODE--writeMode), specifically -wm cg. That will "Create new tags" (c) and "Create new Groups as necessary" (g) but will not write to existing tags.
Title: Re: Copy tag only if it does not exist already
Post by: alta on February 24, 2024, 12:14:14 PM
Thank you, StarGeek. That solved it and it'll be a very useful option to keep in mind.