 struct SdContext {
   FatFile dir;
   File file;
+  uint8_t index;
 };
 
 SdContext RootContext;

    if (index < 2) {
      // Advance to past last file of directory.
      dir_t dir;
      while (curr_dir->readDir(&dir) > 0);
      continue;
    }
    // position to possible previous file location.

    infile->openNext(curr_dir);
    if (infile->isOpen()) {
      if (!infile->isDir() && !infile->isHidden() && !infile->isSystem()) {
        ++curr_index;
#ifdef DEBUG
        char buf[13];
        infile->getName(buf, sizeof(buf));
        cout << F("\nnext opened file ") << (int16_t)curr_index << F(": ") << buf;
#endif
        return;
      }
      infile->close();
    } else {
      curr_dir->rewind();
      curr_index = 0;
    }
  }
}
