simle padding of filenames with 0

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

filmmaker

simle padding of filenames with 0

Post by filmmaker »

very simple, very fast, easy to modify, no fuss, no muss

//************************************************************************************
for (i = 1; i < files.length; i++)
{
var str = '' + i;
switch (str.length){
case 1:
str = '0000' + str;
break;
case 2:
str = '000' + str;
break;
case 3:
str = '00' + str;
break;
case 4:
str = '0' + str;
break;
};
var pse="/";
var fin_3=input_dir+pse+dirs[0]+pse+"sc13b-";
var fin_3=new File(fin_3+str+'.psd');

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

xbytor

simle padding of filenames with 0

Post by xbytor »

Here's how I do it:

Code: Select all function zeroPad(num, w) {
  var str = num.toString();

  while (str.length < w) {
    str = "0" + str;
  }
  return str;
};

var str = zeroPad(20, 4); // returns 0020