Apply a Replace method only to files with one of several extensions

Advanced Renamer forum
#1 : 23/04-15 02:43
Sailor Guy
Sailor Guy
Posts: 23
I have a list of methods that currently does the following rename sequential numbering process:

IMG_4207.jpg --> 20150420-CarRace-001.jpg
IMG_4208.mp4 --> 20150420-CarRace-002.mp4
IMG_4209.jpg --> 20150420-CarRace-003.jpg
IMG_4210.mov --> 20150420-CarRace-004.mov
IMG_4211.jpg --> 20150420-CarRace-005.jpg
IMG_4212.avi --> 20150420-CarRace-006.avi

However, for any video file extensions (.AVI, .MOV, .MP4),
I want to insert the letter "v" in front of the first occurrence of "-"

IMG_4207.jpg --> 20150420-CarRace-001.jpg
IMG_4208.mp4 --> 20150420v-CarRace-002.mp4
IMG_4209.jpg --> 20150420-CarRace-003.jpg
IMG_4210.mov --> 20150420v-CarRace-004.mov
IMG_4211.jpg --> 20150420-CarRace-005.jpg
IMG_4212.avi --> 20150420v-CarRace-006.avi

I know how to use the "Replace" method to replace the first "-" with "v-", but how can I only conditionally apply this method to files with one of several extensions?

Thanks,

Sailor Guy



23/04-15 02:43 - edited 23/04-15 02:44
#2 : 05/05-15 22:47
Sailor Guy
Sailor Guy
Posts: 23
I solved my own question. I wrote a Script method:

var sNewName = item.newName; // new filename.ext

// strip off the auto-added file extension

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

// if file extension is a video file, add a "v" after the
// datestamp (i.e. "20150504v-" instead of "20150504-")
// which is indicated by the first "-" dash in the filename

var sVideoExtList = ".avi .mov .mp4 .mpg";

if (sVideoExtList.search(item.ext.toLowerCase()) > -1) {
sNewName = sNewName.replace("-", "v-");
}

return sNewName;


05/05-15 22:47