Script causing program instability- Possible bug :(

Advanced Renamer forum
#1 : 04/08-13 02:33
Hasan
Hasan
Posts: 3
Hi!

I have a semi-complex renaming pattern so I created the script below. My script DOES work on files (less than 13). When the script is not active (the check box is unchecked), the program can import files or directories fine. However, when I check the box after having imported the files, they become red, error still says "OK" and this alert appears "Access violation at address 6716F7BS in module 'js32.dll'. Read of address 056BF03C."

If I import more than 13 files, and the script is already active, the program shows the same error message and the renaming panel where the old file names are shown along with the new file names becomes blank. The items ARE imported though because when I click on them, their name appears in the item information panel.

After the 13+ files crash, the program can import and show the files when the script is disabled, but crashes even with 2 files (unlike the first case, which worked with up to 12 files).

I uninstalled (had to remove the program's registry keys) and installed it again. The 13 file problem persisted. With the fresh installation, I was able to use my script with under 13 files.

Here is the script:

var oName = item.name; //SMH 52-13-64 writing writing
var noSMH = oName.split("SMH ").pop(); //52-13-64 writing writing
var Fst = noSMH.indexOf("-");
var Snd = noSMH.indexOf("-", Fst+1);
var cleanName = noSMH.substring(0, Snd); //52-13
var numOnly = cleanName.split("-").pop(); //13
var orgSijNum = cleanName.substring(0, cleanName.indexOf('-')); //52-
var addOne = +numOnly + 1;
var minOne = numOnly - 1;
var sep = "+";
var parsed = parseInt(numOnly);

if (parsed %2 == 0){
var evenName = cleanName + sep + addOne ; //52-13+14
return evenName;
}
else{
var oddName = orgSijNum + "-" + minOne + sep + numOnly; //52-13+14
return oddName;
}


04/08-13 02:33
#2 : 05/08-13 16:26
Kim Jensen
Kim Jensen
Administrator
Posts: 870
Reply to #1:
Are you using the latest version of Advanced Renamer? There was an instability bug in a previous version.


05/08-13 16:26
#3 : 05/08-13 18:50
Hasan
Hasan
Posts: 3
Reply to #2:
Yes I am using version 3.58.

I just discovered that it works fine with 13+ files if I disable the Auto Test feature.

Update: The bug is: when the file name does not adhere to the pattern of the script, the access violation alert pops up. So, even Auto Test works if all the names of the directory are, according to my code, like this "SMH ##-##-## writing.jpg"

I have a couple of files that have the name "SMH_53.jpg" which are causing the error. When I removed them, everything worked fine.

I think I can just add an "if" at the beginning of the code to check whether the filename is like that or not, and if it isn't just return file.name.


05/08-13 18:50 - edited 05/08-13 19:33
#4 : 05/08-13 20:20
Hasan
Hasan
Posts: 3
Reply to #3:

This code works fine :)

var oName = item.name; //SMH 52-13-64 writing writing
if (oName.match(/-/) == null) { //Check whether name adheres to pattern or not
return oName;
}
else {
var noSMH = oName.slice(4); //52-13-64 writing writing
var Fst = noSMH.indexOf("-");
var Snd = noSMH.indexOf("-", Fst+1);
var cleanName = noSMH.substring(0, Snd); //52-13
var numOnly = cleanName.split("-").pop(); //13
var orgSijNum = cleanName.substring(0, cleanName.indexOf('-')); //52-
var evenName = "";
var oddName = "";
var addOne = +numOnly + 1;
var minOne = numOnly - 1;
var sep = "+";
var parsed = parseInt(numOnly);

if (parsed %2 == 0){
var evenName = cleanName + sep + addOne ;
return evenName;
}
else{
var oddName = orgSijNum + "-" + minOne + sep + numOnly;
return oddName;
}
}


05/08-13 20:20