How can I set XMP PreservedFileName only if it is empty using ExifTool?
Asked 5/4/2023
40 views
2 answers
0
When batch-processing photos with ExifTool, I often rename files and update metadata multiple times. I want to store the camera/phone’s original filename (without the file extension) in the XMP PreservedFileName tag, but only the first time. Some files in a batch may already have XMP PreservedFileName set, while others may still be empty. Is there an ExifTool command that writes the current filename stem to XMP PreservedFileName only when that tag does not already exist, and otherwise leaves it unchanged?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
3y ago
2 Answers
2
Combining the "write only if not already existing" script snippet from this forum post with the "write preserved filename without file extension" expression from here, you get the wanted behavior:
exiftool "-XMP-xmpMM:PreservedFileName<${filename;s/\.[^.]*$//;$_ = undef if $self->GetValue('xmp:PreservedFileName')}" 'FILEorDIR'
Originally by user109872. Source · Licensed CC BY-SA 4.0
user109872
3y ago
0
Generated from our catalog & community — verify before relying on it.
Yes. You can use an ExifTool assignment expression that copies the current filename without its extension, but cancels the write if XMP:PreservedFileName already exists:
exiftool "-XMP-xmpMM:PreservedFileName<${filename;s/\.[^.]*$//;$_ = undef if $self->GetValue('xmp:PreservedFileName')}" FILEorDIR
How it works:
${filename ...}starts from the current filename.s/\.[^.]*$//removes the file extension.$_ = undef if $self->GetValue('xmp:PreservedFileName')prevents writing anything if the tag is already set.
So files with an empty PreservedFileName get the original filename stem written, while files that already have a value are left untouched.
Recommended products
UniqueBot
AI3y ago
Your Answer
Related Questions
How can I use ExifTool to rename photos with only part of the camera model name?
How do I rename photos by camera model in ExifTool when the model contains a slash?
How can I remove the ImageDescription tag from some Huawei P20 JPEGs so they rename correctly?
How can I shift only the year in photo metadata by 45 years with ExifTool?
How can I rename photo files using the EXIF capture date?