This might help, it is a function taken from my MIDI wave shield sample player. It generates a file name with a number only it uses .wav in place of the .txt that you want.
It builds up the name in an char array which is then passed to the file opening routine.
char toPlay[11]; // string array for file to play 00.WAV to 99999.WAV
void makeName(int number, int depth){ // generates a file name 0.WAV to 9999.WAV suppressing leading zeros
if(number > 9) {
makeName(number / 10, ++depth); // recursion
depth--;
number = number % 10; // only have to deal with the next significant digit of the number
}
toPlay[indexToWrite] = (number & 0xf) | 0x30;
indexToWrite++;
if(depth > 0) {return; } // return if we have more levels of recursion to go
else { // finish off the string with the wave extesion
toPlay[indexToWrite] = '.';
toPlay[1+indexToWrite] = 'W';
toPlay[2+indexToWrite] = 'A';
toPlay[3+indexToWrite] = 'V';
toPlay[4+indexToWrite] = '\0'; // terminator
indexToWrite = 0; // reset pointer for next time we enter
}
}