Cannot make any script work (solved)
Hi, I'm using the latest version of Advanced Rename and I need to use a script.
For now I simply cannot make any script work.
When I type exactly what is shown in:
https://www.advancedrenamer.com/user_guide/v4/method_script
it doesn't work.
______________________________
When I type:
***
odd = !odd;
var val = (odd) ? 'a' : 'b';
return item.newName + '_' + val;
***
I get SyntaxError: return not in a function
______________________________
Let's try to retype the function name:
***
function(index, item) {
odd = !odd;
var val = (odd) ? 'a' : 'b';
return item.newName + '_' + val;
}
***
same error.
______________________________
Let's get to se simplest function possible:
***
return item.newName;
***
same error.
______________________________
Let's get is simpler:
***
item.filename
***
ReferenceError: item is not defined
______________________________
Please could you hemp me to get anything to work?
Then I will enjoy some JS.
Thank you for any help you may give me.
For now I simply cannot make any script work.
When I type exactly what is shown in:
https://www.advancedrenamer.com/user_guide/v4/method_script
it doesn't work.
______________________________
When I type:
***
odd = !odd;
var val = (odd) ? 'a' : 'b';
return item.newName + '_' + val;
***
I get SyntaxError: return not in a function
______________________________
Let's try to retype the function name:
***
function(index, item) {
odd = !odd;
var val = (odd) ? 'a' : 'b';
return item.newName + '_' + val;
}
***
same error.
______________________________
Let's get to se simplest function possible:
***
return item.newName;
***
same error.
______________________________
Let's get is simpler:
***
item.filename
***
ReferenceError: item is not defined
______________________________
Please could you hemp me to get anything to work?
Then I will enjoy some JS.
Thank you for any help you may give me.
Reply to #1:
Did you accidentally put your script into the "Pre batch script" window? Because that will cause such error.
Did you accidentally put your script into the "Pre batch script" window? Because that will cause such error.
Reply to #2:
Thank you very much Kim it's much better.
So global variables can be declared into the "Pre batch script" section. I get it !
Let's enjoy JS now !
Thank you very much Kim it's much better.
So global variables can be declared into the "Pre batch script" section. I get it !
Let's enjoy JS now !
Reply to #3:
Hi Laurent,
Not just global variables; as in your second example above, functions can be defined once in pre-batch. You just need to call them and catch the returns in your main script. This can really speed up processing in long file lists.
For instance: when you regularly deal with series of files with essentially the same name, it is possible to interrogate the first filename in the series and resolve it to your new filename. Then a function in pre-batch checks some portion of the succeeding original filenames against the first filename and, if they are equivalent, just have the function use the original new filename part on all succeeding similar files (adding a unique identifier like <IncNrDir>. You then only need to do the original processing when the file base-name changes. This can save a lot of time in processing the similar files.
Oh, you'll probably have to provide an original name to your functions, not repeat the "function(index, item)" as implied in the main script.
Best,
DF
Hi Laurent,
Not just global variables; as in your second example above, functions can be defined once in pre-batch. You just need to call them and catch the returns in your main script. This can really speed up processing in long file lists.
For instance: when you regularly deal with series of files with essentially the same name, it is possible to interrogate the first filename in the series and resolve it to your new filename. Then a function in pre-batch checks some portion of the succeeding original filenames against the first filename and, if they are equivalent, just have the function use the original new filename part on all succeeding similar files (adding a unique identifier like <IncNrDir>. You then only need to do the original processing when the file base-name changes. This can save a lot of time in processing the similar files.
Oh, you'll probably have to provide an original name to your functions, not repeat the "function(index, item)" as implied in the main script.
Best,
DF