I have a similar requirement but took a different approach.
I start with a file name (w/o extension) of 100,
I add the extension .cvs
I look to see if the file 100.cvs exists
If it does I increment 100 then look for 101.cvs etc
my code is:
do
{
itoa(gFileNumb, gDataFile, 10); // (value, Array, base)
const char *extension = ".csv";
strcat(gDataFile, extension); // syntax: strcat(dest, source)
++gFileNumb;
} while (SD.exists(gDataFile)); // assume will Rtn false if no communication.