Example #1
0
/*
  Description:
    Requrest for a specific file at a specified position within the directory
    The path argument is identical to the path which was provided to last
    call to "mas_sdfat_move_to_pwd"
*/
uint8_t mas_sdfat_get_nth_file(const char *path, uint16_t n, char *buf, uint8_t *is_dir)
{
  uint16_t c = 0;

  if ( mas_sdfat_move_to_pwd(path) == 0 )
    return 0;
  
  if ( mas_sdfat_file_is_open != 0 )
  {
    mas_sdfat_file.close();
    mas_sdfat_file_is_open = 0;
  }
  
  mas_sdfat_sd->vwd()->rewind();
  while (mas_sdfat_file.openNext(mas_sdfat_sd->vwd(), O_READ)) 
  {
    if ( n == c )
    {
      mas_sdfat_file.getFilename(buf);
      buf[12] = '\0';
      *is_dir = mas_sdfat_file.isDir();
      mas_sdfat_file.close();
      return 1;
    }
    c++;
    mas_sdfat_file.close();
  }
  return 0;
}