logic_earth, that's a nice solution to counting the number of files in a directory. The problem is if you had just one file named 20.doc, this method would give you 2.doc rather than 21.doc as altarek says he wants.

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.

The problem is if you had just one file named 20.doc, this method would give you 2.doc rather than 21.doc as altarek says he wants.

Your method counts the number of files in the directory, rather than finding the next unused number in the sequence.. I'm not sure when you would need it to work like this, but altarek presumably knows what he wants. Perhaps files 1.doc to 19.doc get periodically moved to a different location, who knows?