Adding leading zeros to value

Started by Schmidtze, April 09, 2021, 01:01:26 PM

Previous topic - Next topic

Schmidtze

Hi,

I just found this topic https://exiftool.org/forum/index.php?topic=11054.0 (Subsec workaround for Olympus: read shot sequence number from tag "Drive Mode"). I'm using this now in a batch file for adding the shot number of continuous shots to my filenames:

Quoteexiftool -if "$drivemode =~ /Continuous/" "-FileName<${EXIF:DateTimeOriginal}_${drivemode;$_ = /Shot (\d+)/ ? $1 : undef}%%-c.%%le" -d "%%Y-%%m-%%d-%%H%%M%%S" %1

It does now nearly what I want. But i didn't find out by now, how to add always 2 digits for the shot numbers, with leading zeros for numbers lower than 10. Is this possible?

Many thanks in advance and best regards
Friedemann

Phil Harvey

Hi Friedemann,

Try this:

exiftool -if "$drivemode =~ /Continuous/" "-FileName<${EXIF:DateTimeOriginal}_${drivemode;$_ = /Shot (\d+)/ ? sprintf('%.2d',$1) : undef}%%-c.%%le" -d "%%Y-%%m-%%d-%%H%%M%%S" %1

- 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 ($).

Schmidtze

Hi Phil,

many thanks for the quick answer!  :)

With your suggestion

exiftool -if "$drivemode =~ /Continuous/" "-FileName<${EXIF:DateTimeOriginal}_${drivemode;$_ = /Shot (\d+)/ ? sprintf('%.2d',$1) : undef}%%-c.%%le" -d "%%Y-%%m-%%d-%%H%%M%%S" %1

I get this on the commandline

Warning: Can't find string terminator "'" anywhere before EOF for 'drivemode' - 0262.dng

and a filename like "0262.dng" becomes

2021-03-28-144320_Continuous Shooting, Shot 3; Electronic shutter.dng

instead of

2021-03-28-144320_03.dng

Best regards
Friedemann

StarGeek

Batch file?  Try doubling the % sign
sprintf('%%.2d',$1)
"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

Schmidtze

Oh yes, of course, doubling the % did the job...  :-[

Many many thanks, to you both, it works perfect now!  :)

Best regards
Friedemann