How can I use ExifTool to rename photos with only part of the camera model name?
Asked 5/3/2019
7 views
2 answers
0
I’m using ExifTool to rename image files based on metadata, and I want the filename to include the camera model plus the capture date. My current command uses the Model tag, but for some cameras that tag contains a long full name like NIKON D750 or KODAK DC280 ZOOM DIGITAL CAMERA.
Example command:
exiftool -d %Y-%m-%d_%H%M%%-c.%%e "-filename<${model;}_$CreateDate" -r DIRECTORY
That produces filenames such as:
NIKON D750_2019-03-07_2156.nefKODAK DC280 ZOOM DIGITAL CAMERA_1999-05-31_1200.jpg
I’d prefer shorter model-only names such as D750 or DC280 if possible. There doesn’t seem to be a better EXIF tag available for these files.
Can ExifTool do this directly with tag transformations or regular expressions?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
7y ago
2 Answers
2
You can do this with ExifTool using a regular expression. I use this:
exiftool $TARGET '-filename<${createdate}_${model;s/-//g;s/ //g;tr/A-Z/a-z/}_${filename;tr/A-Z/a-z/}' -d %Y%m%d
which removes dashes and spaces and lower-cases the tag — it's the ${model;s/-//g;s/ //g;tr/A-Z/a-z/} part. You can use basically any perl-compatible regular expression there to do the transformation. If you're not familiar with this, you can read a bit more in the perl docs or on other tutorials online. The specifics of this scripting is out of scope for photography, I think, but this should get you started.
Originally by user1943. Source · Licensed CC BY-SA 4.0
user1943
7y ago
0
Generated from our catalog & community — verify before relying on it.
Yes. ExifTool can transform the Model tag during renaming using its inline Perl-style substitutions.
From the example provided, this pattern works:
-filename<${createdate}_${model;s/-//g;s/ //g;tr/A-Z/a-z/}_${filename;tr/A-Z/a-z/}
The important part is:
${model;...}
That lets you apply substitutions to the Model value before it is written into the filename. For example, you can remove spaces, remove dashes, change case, or use a regex to strip unwanted words.
So yes, ExifTool can do this directly; you don’t need a separate renaming program. The exact regex needed to turn names like NIKON D750 into D750 or KODAK DC280 ZOOM DIGITAL CAMERA into DC280 depends on how consistent your camera model strings are, but ExifTool supports that kind of text cleanup inline.
If you’re not familiar with the syntax, look up ExifTool tag-value interpolation and Perl regular expressions.
Recommended products
UniqueBot
AI7y ago
Your Answer
Related Questions
How do I rename photos by camera model in ExifTool when the model contains a slash?
How do I get ExifTool to rename .HEICS files using the file modify date?
How can I set XMP PreservedFileName only if it is empty using ExifTool?
How can I change the camera model in a RAW file using ExifTool?
Can exiv2 delete an EXIF tag by hexadecimal ID if the tag name is unknown?