I have a camera that uses a SequenceNumber tag. I have another camera that uses a FileNumber tag. Both of these tags essentially give a file a unique number when multiple shots are captured in a burst.

I'd like to use this to rename my files to unique filenames like this:

  • if SequenceNumber exists: DateTimeOriginal-SequenceNumber.ext
  • if FileNumber exists: DateTimeOriginal-FileNumber.ext
  • if neither exists, don't change

Separately, I can use the following commands:

exiftool -d '%Y%m%d%H%M%S' '-FileName<${DateTimeOriginal}-${SequenceNumber}.%e' *.ARW
exiftool -d '%Y%m%d%H%M%S' '-FileName<${DateTimeOriginal}-${FileNumber}.%e' *.NEF

How do I construct the exiftool command to do this together?

I suppose I can run these commands separately based on different file extensions in a shell script, but I understand exiftool has conditional capability and I'd like to learn how to use this if possible.


1 Answer 1


From the docs under the -TAG[+-^]=[VALUE] option, note #1

  1. Many tag values may be assigned in a single command. If two assignments affect the same tag, the latter takes precedence…

You can put both options together in the command with the one that would have precedence in the case that some file has both tags as the last option

exiftool -ext nef -ext arw -d '%Y%m%d%H%M%S' '-FileName<${DateTimeOriginal}-${SequenceNumber}.%e' '-FileName<${DateTimeOriginal}-${FileNumber}.%e' /path/to/files/

Here I used the -ext (-extension) option to limit processing to just nef and arw files. See ExifTool Common Mistake #2 for the pitfalls of using wildcards to limit file types.

Finally, you want to avoid adding the -m (-ignoreMinorErrors) option for this command, as adding that will return a tag with an empty string rather than an undefined tag which would cause that part of the command to be skipped.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.