Why is only the last step in my script not working? The rest is working ok.
Error: file number 30 should have name C, but it gets name A from this statement below.
Why is this loop not renaming file 30 with C? (as is the rest renamed C correct)
Details:
I am using a script to rename files. I have 3 names in a sequence A, B and C.
The first 10 files are renamed with A
The next 10 with B
The next 10 with C
Then the next 10 again with A
Then the next 10 with B
etc.
Script/ statement
var X = 3; //sequence steps
var Y = 10; //files per sequence step
if (counter) {
index = (counter)%(X*Y);
if (index <= Y) newName += '_A_';
else if (index <= Y*2) newName += '_B_';
else if (index <= Y*3) newName += '_C_';
}
I have isolated this problem to be only in the last number of the last sequence step (C in this example). The rest is working ok.
2
Answers
try:
You did not post your code for what
counter
is. You should update your question to include this as it is pretty important for what went wrong. I will update my answer if you do this.I will say that you should update your code in a few ways to be clearer, cleaner, and more modern. First, use
const
orlet
instead ofvar
. Second, name your variables something useful, not just single letters or abbreviations. This will make your code much easier to read. Next, when doing anything other than perhaps a single if statement, always use brackets in your if/else statements.Doing it this way will look much cleaner and help you and others to spot problems. Please update your question to include where you defined the
count
variable with the loop code and then I will be able to update this answer with a more clear solution.You may also consider adding console.log() statements inside the loop to log the value of index and counter in order to see what those values are when the problem is occurring.