Scripting Method: trouble during folder renaming containing the char . (dot or point)

Advanced Renamer forum
#1 : 22/11-12 19:10
NomenEtOmen
NomenEtOmen
Posts: 29
i've written a script for renaming folder names. but when the name contains the character . , the item.name-property gives wrong content :

here my script for testing:

<code>
/*
list of words: last word to front, separated with ,
words words word -> word, words words
*/
var oName = item.name; //original name
var nName = ""; //new name
var last = ""; //last word
var help = "";
var sSep = ","; //the separator after first word

//processing error when name contains .
//workaround: mask . with other char: ~
var bWorkAround = 1; //workaroung active
if (bWorkAround && oName.indexOf(".")>=0){
oName = oName.replace(/\./g,"~");
}


//algorithm selection
var algorithm = "split"; //substr extract with substr-technology
//split use split and rebuild
if (algorithm=="substr"){
/* substr-index-variante */
var nLastIndex = oName.lastIndexOf(" ");
if (nLastIndex<=0) {
//no space found
return;
}
last = oName.substring(nLastIndex);
nName = last + sSep + " " + oName.substr(0,nLastIndex);


} else if (algorithm=="split"){
/* split-variante */
var comp = oName.split(" ");
if (comp.length<=1) {
//no spliting
return;
}
//it has splitted :-)
last = comp.pop() + sSep;
comp.unshift(last);
nName = comp.join(" ");

} else {
//unsigned algorithm -> error
return;
}

//tried workaround: de-masking . with ~
if (bWorkAround && nName.indexOf("~")>=0){
nName = nName.replace(/~/g,".");
}

//script-end: new name
//item.newName = nName;
return nName;
</code>


first, i thought i'm wrong with the split-method, so i implemented an alternative algorithm using String-object-methods substr and substring. But nothing works, so i programmed a workaround with masking the . with ~, but no luck.


22/11-12 19:10 - edited 22/11-12 19:11
#2 : 23/11-12 20:42
Kim Jensen
Kim Jensen
Administrator
Posts: 870
Reply to #1:
Even though folders don't usually have extensions, Advanced Renamer will treat everything after the last . as a filename extension, even for folders. Have you tried to change the Apply To combobox to Name & Extension?


23/11-12 20:42
#3 : 26/11-12 18:14
NomenEtOmen
NomenEtOmen
Posts: 29
Reply to #2:
you're right. with the option "name&extension" it seems to work proper. that's good for me.

thx


26/11-12 18:14