%C with defined number of digits?

Started by LookTouch Photo, September 23, 2020, 01:14:27 PM

Previous topic - Next topic

LookTouch Photo

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.
OS Windows10

StarGeek

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

LookTouch Photo

Thanks for your quick answer. Yes it works! I will now try to figure out what it actually does.  ;)
exiftool rocks!
OS Windows10

StarGeek

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

LookTouch Photo

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.
OS Windows10

Phil Harvey

It is worth browsing the list of Extra Tags -- some of these can be very useful.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

LookTouch Photo

OS Windows10

LookTouch Photo

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?

OS Windows10

StarGeek

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype