Wave Shield Adafruit - Play next song and previous song

The easiest way would be to declare a fixed array of strings (maybe 20?) and then copy the filenames into that array, taking care not to exceed your predefined max.

const int maxFilenames = 20;
String filenames[maxFilenames];


int readFileList(FatReader &d)
{
  int currentFileIndex = 0;
  while (readDir(dirBuf) > 0) {     // read the next file in the directory
    // skip subdirs . and ..
    if (dirBuf.name[0] == '.')
      continue;

    String[currentFileIndex] = dirBuf.name;
    currentFileIndex++;

    if ( currentFileIndex == maxFilenames ) {
      break;  // all full, don't read any more
    }
  return currentFileIndex;
}

Then, inside setup(), you call this function which returns the number of files read and you simply index forward or backward with some variable (maybe currentIndex?) taking care to wrap around from 0..numer of files read.

I'll leave that as an exercise for you :slight_smile: