Pad beginning of returned tag value

Started by mrdpenguin, January 08, 2017, 06:11:13 PM

Previous topic - Next topic

mrdpenguin

I have a complex file renaming methodology that I use where I have a bunch of fields that I require to all be fixed width. One of those fields is the FileIndex. This is for CR2 file renaming. When I use the -filename option to rename the file and use the FileIndex as part of the new file name, is there a way to force it to be fixed length and pad the beginning with a defined number of zeros?

StarGeek

#1
There's a few ways to do it.  For example, to pad to 5 digits
"-Filename<${FileIndex;$_=sprintf('%05d',$_)}"

"-Filename<${FileIndex;$_=substr('00000'.$_,-5)}"

"-Filename<${FileIndex;$_='0' x (5-length).$_}"

Necro Edit: The first method drops trailing digits if too long.  For example, if FileIndex was 123456, then the result would be 12345.  The other two drop leading digits, e.g. 123456 would become 23456.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).