You already asked this before and got a couple of smart ideas:
-Instead of using numbers, use timestamp since you don’t have to do any check about the name being unique.
-Getting a list of names of file in the directory and extracting the highest number (similar to @qbrandon’s suggestion).
Please take some time to try them before posting the same problem in a different way.