ExifTool Forum

ExifTool => Newbies => Topic started by: Schmidtze on April 09, 2021, 01:01:26 PM

Title: Adding leading zeros to value
Post by: Schmidtze on April 09, 2021, 01:01:26 PM
Hi,

I just found this topic https://exiftool.org/forum/index.php?topic=11054.0 (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
Title: Re: Adding leading zeros to value
Post by: Phil Harvey on April 09, 2021, 01:57:52 PM
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
Title: Re: Adding leading zeros to value
Post by: Schmidtze on April 09, 2021, 06:25:58 PM
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
Title: Re: Adding leading zeros to value
Post by: StarGeek on April 09, 2021, 06:42:08 PM
Batch file?  Try doubling the % sign
sprintf('%%.2d',$1)
Title: Re: Adding leading zeros to value
Post by: Schmidtze on April 09, 2021, 06:45:37 PM
Oh yes, of course, doubling the % did the job...  :-[

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

Best regards
Friedemann