How would that code I posted give you 2 instead of 21? That makes no logical sense. We are pulling in all files that match the pattern and counting them. If their is 20 files we will get 21 within "$next" as it should be.
Please, elaborate how you got 2 when adding one to 20.
You need to examine my code more closely. You should see I am using "count() + 1" directly. If there are 20 files, count() will be 20, what happens then? We will get 21 from the plus one.