If all the files are in the same folder (that's why I asked earlier), you could use the approach in this script:
You'll need to modify it slightly, but not much. That script avoids using duplicate numbers, but will use a number lower than the current maximum if there's a gap (e.g. due to an old file being moved or deleted). But it should be fairly easy to make it always use the next highest number.