Increment Serial Number using EXIF

902 views Asked by At

I am using ExifTool to change the camera body serial number to be a unique serial number for each image in a group of images numbering several hundred. The camera body serial number is being used as a second place, in addition to where the serial number for the image is in IPTC, to put the serial number as it takes a little more effort to remove.

The serial number is in the format ###-###-####-#### where the last four digits is the number to increment. The first three groups of digits do not change for each batch I run. I only need to increment that last group of digits.

EXAMPLE I if I have 100 images in my first batch, they would be numbered:

811-010-5469-0001, 811-010-5469-0002, 811-010-5469-0003 ... 811-010-5469-0100

I can successfully drag a group of images onto my ExifTool Shortcut that has the values

exiftool(-SerialNumber='001-001-0001-0001') 

and it will change the Exif SerialNumber Tag on the images, but have not been successful in what to add to this to have it increment for each image.

I have tried variations on the below without success:

exiftool(-SerialNumber+=001-001-0001-0001)
exiftool(-SerialNumber+='001-001-0001-0001')

I realize most likely ExifTool is seeing these as numbers being subtracted in the first line and seeing the second line as a string. I have also tried:

exiftool(-SerialNumber+='1')
exiftool(-SerialNumber+=1)

just to see if I can even get it to increment with a basic, single digit number. This also has not worked.

Maybe this cannot be incremented this way and I need to use ExifTool from the command line. If so, I am learning the command line/powershell (Windows), but am still weak in this area and would appreciate some pointers to get started there if this is the route I need to take. I am not afraid to use the command line, just would need a bit more hand holding then normal for a starting point. I also am learning Linux and could do this project from there but again, not afraid to use it, just would need a bit more hand holding to get it done.

I do program in PHP, JavaScript and other languages so code is not foreign to me. Just experience in writing it for the command-line.

If further clarification is needed, please let me know in the comments.

Your help and guidance is appreciated!

2

There are 2 answers

10
StarGeek On BEST ANSWER

You'll probably have to go to the command line rather than rely upon drag and drop as this command relies upon ExifTool's advance formatting.

Exiftool "-SerialNumber<001-001-0001-${filesequence;$_=sprintf('%04d', $_+1 )}" <FILE/DIR>

If you want to be more general purpose and to use the original serial number in the file, you could use

Exiftool "-SerialNumber<${SerialNumber}-${filesequence;$_=sprintf('%04d', $_+1 )}" <FILE/DIR>

This will just add the file count to the end of the current serial number in the image, though if you have images from multiple cameras in the same directory, that could get messy.

As for using the command line, you just need to rename to remove the commands in the parens and then either move it to someplace in the command line's path or use the full path to ExifTool.

As for clarification on your previous attempts, the += option is used with numbers and with lists. The SerialNumber tag is usually a string, though that could depend upon where it's being written to.

0
Ansgar Wiechers On

If I understand your question correctly, something like this should work:

1..100 | % {
  $sn = '811-010-5469-{0:D4}' -f $_

  # apply $sn
}

or like this (if you iterate over files):

$i = 1
Get-ChildItem 'C:\some\folder' -File | % {
  $sn = '811-010-5469-{0:D4}' -f $i

  # update EXIF data of current file with $sn

  $i++
}