Tricky sequential renumbering with a suffix

Advanced Renamer forum
#1 : 23/04-15 03:21
Sailor Guy
Sailor Guy
Posts: 23
I have a list of photo files that I want to sequentially renumber.

IMG_4207.jpg --> CarRace-001.jpg
IMG_4208.jpg --> CarRace-002.jpg
IMG_4209A.jpg --> CarRace-003A.jpg
IMG_4210B.jpg --> CarRace-003B.jpg
IMG_4211.jpg --> CarRace-004.jpg
IMG_4212.jpg --> CarRace-005.jpg
IMG_4213A.jpg --> CarRace-006A.jpg
IMG_4214B.jpg --> CarRace-006B.jpg
IMG_4215.jpg --> CarRace-007.jpg
IMG_4216.jpg --> CarRace-008.jpg

The challenge is some photos are front and back images with a suffix of "A" (front) or "B" (back) and I want to rename them with the same sequence number plus the "A" or "B" suffix.

Is there a way to accomplish this with a version of the Add "-<Inc NrDir:001>" method or a script method?

Thanks,

Sailor Guy


23/04-15 03:21
#2 : 05/05-15 22:51
Sailor Guy
Sailor Guy
Posts: 23
I solved my own question with a Script method:

// If a filename has a "$A" or "$B" in its name, it means
// it is a "front" and "back" photo, so there are two image files
// for each (A=front, B=back). Remove the "$" sign and for
// the "B" back photo, change the sequence number to match
// the "A" front photo filename sequence number

var sName = item.name; // original (unchanged) filename.ext
var sNewName = item.newName; // new filename.ext
var sFrontBackChar = "A"; // "A" = Front / "B" = Back

// strip off the auto-added file extension
// look for the last "." period in the filename+extension

sNewName = sNewName.substr(0,sNewName.lastIndexOf("."));

// strip off the file seq number (going to build a new one)
// look for last "-" dash in the filename

sNewName = sNewName.substr(0,sNewName.lastIndexOf("-"));

sFrontBackChar = ""; // assume no "front/back" images

if (sName.search("\\$A") > -1) {
sFrontBackChar = "A"; // "A" - front image
}

if (sName.search("\\$B") > -1) {
sFrontBackChar = "B"; // "B" - back image
iSeqNum = iSeqNum - 1; // keep the image seq number the same as last image
}

iSeqNum = iSeqNum + 1; // increment file seq number counter

// build the zero-left-padded file sequence number string

sSeqNum = "0000000000".concat(iSeqNum.toString());
sSeqNum = sSeqNum.substr(sSeqNum.length - iSeqNumChars);

// ...and append the file seq string to the filename

sNewName = sNewName.concat("-" + sSeqNum + sFrontBackChar);

return sNewName;


05/05-15 22:51
#3 : 19/04-16 12:34
joci
joci
Posts: 10
Reply to #2:
Good afternoon.
Is this script work?
I do not get it working
Greetings Jon


19/04-16 12:34