Better late than never? An apology of sorts...
While looking for some information for HOBBS on his question about pasting Python scripts I came across an old post. Back in April 2024 an "RJ Barber" posted a thread about removing words from a group of filenames by using an iterable: https://www.advancedrenamer.com/forum_thread/help-with-scrip ting-14352
I gave him an answer, but it wasn't complete. I say that because I don't think the answer was wrong, I just didn't see the problem at the time (I was still, and am still, learning javascript in relation to ARen). The thread is locked, so I can't tack this on the end, but maybe adding it here will help someone in the future.
The script I gave him was:
Pre-batch script (in the prebatch script this will only execute once, instead of each time you step through the files):
// ----------------------------------------------
var substrings = ["Whatever","you","need"];
// ----------------------------------------------
Main script:// ----------------------------------------------
var myName = item.newName;
for (var i = 0; i < substrings.length; i++){
if ( item.newName.includes(substrings[i])){
myName = myName.replace(substrings[i],"")
}
}
return myName;
// ----------------------------------------------
The answer was correct, but not complete. He tried it and said it was adding a second (duplicate) extension to his filenames. NOW I immediately see that he needed to either:
1. Change the Apply to: field to "Name and extension", or
2. Change all occurrences of "item.newName" in the script to "item.newBasename".
Either would have fixed his problem, but I didn't realize / think of it at the time. He said he had thousands of files, so even with going back and adding some methods to fix the dupe extensions I'm sure he saved a *lot* of time and effort, but still... I feel bad for my inexperience.
So, I apologize for not being more specific in the use of that script. Sorry RJ, if you are around.
Best,
DF
I gave him an answer, but it wasn't complete. I say that because I don't think the answer was wrong, I just didn't see the problem at the time (I was still, and am still, learning javascript in relation to ARen). The thread is locked, so I can't tack this on the end, but maybe adding it here will help someone in the future.
The script I gave him was:
Pre-batch script (in the prebatch script this will only execute once, instead of each time you step through the files):
// ----------------------------------------------
var substrings = ["Whatever","you","need"];
// ----------------------------------------------
Main script:// ----------------------------------------------
var myName = item.newName;
for (var i = 0; i < substrings.length; i++){
if ( item.newName.includes(substrings[i])){
myName = myName.replace(substrings[i],"")
}
}
return myName;
// ----------------------------------------------
The answer was correct, but not complete. He tried it and said it was adding a second (duplicate) extension to his filenames. NOW I immediately see that he needed to either:
1. Change the Apply to: field to "Name and extension", or
2. Change all occurrences of "item.newName" in the script to "item.newBasename".
Either would have fixed his problem, but I didn't realize / think of it at the time. He said he had thousands of files, so even with going back and adding some methods to fix the dupe extensions I'm sure he saved a *lot* of time and effort, but still... I feel bad for my inexperience.
So, I apologize for not being more specific in the use of that script. Sorry RJ, if you are around.
Best,
DF