Read filename from SD card, store to a string

I cant seem to figure out how to read a file name of a file I have on SD card, and save the file name (not its contents, just the file name itself) to a string.

Nor, it seems, can you figure out how to post your code.

Can someone point me in the right direction for reading the file name, say 0001.mp3, and saving this an int variable. So it will be 1 to 9999.

int num = 0;
while(file.available() > 0)
{
   char ltr = file.read();
   if(ltr >= '0' && ltr <= '9')
   {
      num *= 10;
      num += ltr - '0';
   }
   else // found the ., the m, the p, the 3, the <cr>, or the <lf>
   {
      // Save num somewhere

      num = 0;
   }
}