How do I include the original file number in an ExifTool rename pattern?
Asked 6/29/2024
5 views
2 answers
0
I’m using ExifTool to rename files based on CreateDate, for example:
exiftool -d "%Y/%m/%y-%m-%d %H-%M-%S 0%%c.%%e" '-filename<$CreateDate' .
If the source filename is something like IMG_7198.HEIC, I want to extract the numeric part (7198) from the original basename and include it in the destination filename along with the date/time. How can I do that in the ExifTool format string?
Originally by kas. Source · Licensed CC BY-SA 4.0
kas
1y ago
2 Answers
2
You can use the %f variable and edit it as described in the "Advanced Features" section of the -w (-TextOut) option.
The %f variable hold the base filename of the file. Since you want to drop the first 4 characters, you would use .4 between the percent sign and the f, e.g. %.4f. This would leave you with just the numbers.
Because this will be used in a -d (-dateFormat) format string, the % signs need to be doubled, similar to what is done with the %c and %e in your example command.
In this resulting command, I replaced your origianl 0%%c with %%.2c. This causes the %c count variable to be automatically padded to two numbers, i.e. it will number 01-09 and then proceed with 10+
exiftool -d "%Y/%m/%y-%m-%d %H-%M-%S %%.4f %%.2c.%%e" '-filename<$CreateDate' .
Originally by StarGeek. Source · Licensed CC BY-SA 4.0
StarGeek
1y ago
0
Generated from our catalog & community — verify before relying on it.
Use ExifTool’s %f variable, which represents the original base filename (without extension), and trim off the fixed prefix.
For a name like IMG_7198.HEIC, %.4f drops the first 4 characters of the basename, leaving 7198.
Because you’re using this inside a -d date-format string, the percent signs must be doubled:
exiftool -d "%Y/%m/%y-%m-%d %H-%M-%S %%.4f %%.2c.%%e" '-filename<$CreateDate' .
What this does:
%Y/%m/...builds folders/filename fromCreateDate%%.4finserts the original file number from the basename%%.2cadds ExifTool’s copy number padded to 2 digits (01,02, etc.) if needed%%ekeeps the original extension
So IMG_7198.HEIC can become something like:
2024/05/24-05-10 14-32-18 7198 01.HEIC
This works when the prefix length is consistent, such as IMG_ always being 4 characters.
Recommended products
UniqueBot
AI1y ago
Your Answer
Related Questions
How do I get ExifTool to rename .HEICS files using the file modify date?
How can I use ExifTool to rename photos with only part of the camera model name?
How do I include a shell variable in an ExifTool rename path?
How can I batch rename photos by date and check for out-of-order timestamps?
How do I use jhead to rename photos by date with a sequential counter?