Reading from file in Arduino IDE

I have folder contain of many text files and I want to read data in specific range for example (read each 100 value after another) .
How can I do that by using esp32 ?
any advice?

Where is this folder situated ?

On my PC.

Then you either need an application on the PC to send the data to the ESP or you could copy the folder to an SD card and attach that directly to the ESP and read the files from there

@alex_al we kinda guessed that :rofl:

Maybe a little more detail would help.

What is the APP ?
like esp32wroom did not have SD card .

If the data is dynamic and not applicable to using SPIFFS, then you could set-up a webserver on the PC/rPi and have the ESP32 request the data in chunks. You could also use some ESP32 flash to buffer long-term data noting that you do introduce some flash wear.

You can add an SD if your ESP32 module lacks one; or, purchase a model with SD.

You could add a bigbutt eeprom to the ESP to buffer OTA/FTP again realizing that the PC must participate.

On an ESP8266, one can successfully load the entire OUI text data into SPIFFS. https://ouilookup.com/
(pretty cool)

Have a look at text editors or you maybe able to import into word and move about in 100 step increments .

I used SPIFFS and I used this function

void readFile(fs::FS &fs, const char * path){
   Serial.printf("Reading file: %s\r\n", path);

   File file = fs.open(path);
   if(!file || file.isDirectory()){
       Serial.println("− failed to open file for reading");
       return;
   }
   
   int count = 0;
   Serial.println(" read from file:");

   while(file.available()){
    if (count < 100)  
      Serial.write(file.read());  
   } 
}

What is the alternative function for "file.read()" something like "readline" because I need to read the file from first line to 100,

Most functions are shown here:
https://randomnerdtutorials.com/esp32-microsd-card-arduino/

You may need to just count end-of-line termination (CR/LF) to process line-count.
The SD commands from source are:

typedef enum {
    GO_IDLE_STATE           = 0,
    SEND_OP_COND            = 1,
    SEND_CID                = 2,
    SEND_RELATIVE_ADDR      = 3,
    SEND_SWITCH_FUNC        = 6,
    SEND_IF_COND            = 8,
    SEND_CSD                = 9,
    STOP_TRANSMISSION       = 12,
    SEND_STATUS             = 13,
    SET_BLOCKLEN            = 16,
    READ_BLOCK_SINGLE       = 17,
    READ_BLOCK_MULTIPLE     = 18,
    SEND_NUM_WR_BLOCKS      = 22,
    SET_WR_BLK_ERASE_COUNT  = 23,
    WRITE_BLOCK_SINGLE      = 24,
    WRITE_BLOCK_MULTIPLE    = 25,
    APP_OP_COND             = 41,
    APP_CLR_CARD_DETECT     = 42,
    APP_CMD                 = 55,
    READ_OCR                = 58,
    CRC_ON_OFF              = 59
} ardu_sdcard_command_t;


https://github.com/espressif/arduino-esp32/blob/master/libraries/SD/src/sd_diskio.cpp

For SPIFFS, I read the entire OUI and process like: (snippet)
Spiff_OUI-13.ino (10.7 KB)

timeMarker = millis() + 5000;
  FileRead = SPIFFS.open("/oui.txt", "r") ;
  FileRead.seek(fileByteOffset, SeekSet) ;                              // Seek to record

    while (ok && FileRead.available() > 0)                              // While not EOF
    {
      currentCharacter = FileRead.read() ;

      if (OUI_match_Index < 8 )  {                                      // gather the first 8 characters of a line as: xx-xx-xx
        cArrayOUI[OUI_match_Index] = currentCharacter ;
        ++OUI_match_Index ;
      }

      if (currentCharacter == 9) {                                      // TAB ?
          cOctet1 = (ASCII2HEX(cArrayOUI[1])) + (ASCII2HEX(cArrayOUI[0]) * 16) ;
          cOctet2 = (ASCII2HEX(cArrayOUI[4])) + (ASCII2HEX(cArrayOUI[3]) * 16) ;
          // the magic in the test below is only possible because the imported OUI list is in order by 1st::2nd octet
          if ((cOctet2 > oui_array[iRecIdx - 1].c_Octet2) || ( cOctet1 > oui_array[iRecIdx - 1].c_Octet1)) 
          {
            oui_array[iRecIdx].c_Octet1 = cOctet1 ;
            oui_array[iRecIdx].c_Octet2 = cOctet2 ;                     // iRecIdx points to last-built array elements
            oui_array[iRecIdx].f_offset = (currentPosition - previousPosition) ;
            previousPosition = currentPosition ;


            if( millis() > timeMarker ) {
              Serial.print(".") ;                                       // Let user know something is happening
              timeMarker = millis() + 5000 ;
            }
            OUI_match_Index = 0 ;                                       // prepare for next OUI parsing
            OUI_matchup = "" ;                                          // null out the capture String;
            ++iRecIdx ;                                                 // Block count
        }
      }

      if (currentCharacter == 10)                                       // End-of-line ?
      {
          // previousPosition  = currentPosition ;                         // Delta
          currentPosition   = FileRead.position() ;                     // DO NOT nest this function
          OUI_match_Index = 0 ;                                         // prepare for next OUI parsing
          OUI_matchup = "" ;                                            // null out the capture String;
      }
    }                                                                   // EOF

    Serial.print( "\n\rReached End Of File\n\r") ;
}