ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: LookTouch Photo on September 23, 2020, 01:14:27 PM

Title: %C with defined number of digits?
Post by: LookTouch Photo on September 23, 2020, 01:14:27 PM
I am copying files with this command (OS W10)

exiftool -d "\%Y\%m\%d_%H%M_%S%%.2C_C5.%%e" "-filename<targetdir${createdate}" "sourcedir"

I need to use %.2C rather than %.2c because all my filenames must have 15 characters plus extension e.g. 21_1536_1299_C5.ARW (of course in directory 2020\09\)
However the %.2C counter does not wrap around 98, 99, 00, 01, . . . but rather extends to three digits 98, 99, 100, 101, . . .
Is there a way I can confine the counter to values 00..99? I could do it with a second step but would prefer not to.

I tested it only with 5 files using a starting value like %98.2C. I would assume the behavior is identical with %.2C and 100+ files. In my workflow it is impossible for more than 99 images to be created in the same second. So the values 00..99 guarantees unique filenames.
Title: Re: %C with defined number of digits?
Post by: StarGeek on September 23, 2020, 04:28:13 PM
You're probably have to use FileSequence instead of %C.  Try this
exiftool -d "\%Y\%m\%d_%H%M_%S" "-filename<targetdir${createdate}${FileSequence;$_%=100;$_=sprintf('%02d',$_ )}_C5.%e" "sourcedir"

This will act differently than the %C in some cases, so test it out.
Title: Re: %C with defined number of digits?
Post by: LookTouch Photo on September 25, 2020, 05:09:47 AM
Thanks for your quick answer. Yes it works! I will now try to figure out what it actually does.  ;)
exiftool rocks!
Title: Re: %C with defined number of digits?
Post by: StarGeek on September 25, 2020, 11:28:48 AM
The $_ is Perl's default variable.  In the context of exiftool, it holds the value of the tag.  Any value assigned to it becomes the new value of the tag.

The % in this context is the modulus operator.  It gives the remainder of a division operation.  Adding the equal sign to it makes it the modulus assignment operator.  It would be the same as $a = $a%100.  The end result is a number from 0 to 99.

The sprintf is there to pad any single digit result (0-9) with a leading 0.
Title: Re: %C with defined number of digits?
Post by: LookTouch Photo on September 25, 2020, 11:38:43 AM
Thanks again!
Is there a place where FileSequence and probably other special tags are documented? Is this a PERL thing? I can,'t find it on exiftool.org.
Title: Re: %C with defined number of digits?
Post by: Phil Harvey on September 25, 2020, 12:12:10 PM
It is worth browsing the list of Extra Tags (https://exiftool.org/TagNames/Extra.html) -- some of these can be very useful.

- Phil
Title: Re: %C with defined number of digits?
Post by: LookTouch Photo on September 25, 2020, 12:14:04 PM
will do!
Title: Re: %C with defined number of digits?
Post by: LookTouch Photo on September 27, 2020, 07:01:53 AM
Just realized there is an issue if sidecar files are already present before the renaming. The $filesequence is applied to the image file and the xmp file. E.g.

dsc001.arw
dsc001.xmp

becomes

10_1742_3300_C5.ARW
10_1742_3301_C5.XMP

which is undesirable. I do understand that $filesequence only does what it is supposed to do. Would you have a suggestion how to keep the naming "bond" between image and sidecar file intact?

Title: Re: %C with defined number of digits?
Post by: StarGeek on September 27, 2020, 12:07:45 PM
Yeah, this is the type of unintended consequences I thought might happen.  I can't see a way to rename both the file and the sidecar using the FileSequence tag.  You're probably better off with your original thought of a two step solution.