ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Theo on January 18, 2022, 06:44:40 PM

Title: Renaming syntax
Post by: Theo on January 18, 2022, 06:44:40 PM
Hi all,
sorry for maybe a trivial question. I'd like to rename the files by shuttercount in six-digit format (eg. 012345), but I can't figure out the correct pattern. Can someone please help me? Thanks.

exiftool -if "${ShutterCount}" "-FileName<${ShutterCount}_%f%E" -r .
Title: Re: Renaming syntax
Post by: StarGeek on January 18, 2022, 07:29:17 PM
From this previous post (https://exiftool.org/forum/index.php/topic,7974.msg40666.html#msg40666)

"-Filename<${ShutterCount;$_=sprintf('%06d',$_)}"_%f%E"

"-Filename<${ShutterCount;$_=substr('000000'.$_,-6)}"_%f%E"

"-Filename<${ShutterCount;$_='0' x (6-length).$_}"_%f%E"

Plus a new one userful for padding multiple occurances of numbers already part of a string (e.g. "7 of 9" -> "007 of 009"), a variation of the first one.  Not as useful for this purpose, but adding it so I can link to this post at a later date.
"-Filename<${ShutterCount;s/([0-9]+)/sprintf('%06d',$1)/ge}"_%f%E"
Title: Re: Renaming syntax
Post by: Theo on January 21, 2022, 02:39:24 PM
Totally did it. Thank you for the quick answer!