want to know how many files are in a SD card

i have this code , but it only counts from 1 to 26 and then stops but i have about 105 files there
in the root , want i am doing wrong , my be its not made this lame way.. :slight_smile:

int maximo=0;  //this i declared global





void numerofilessdcard() {
 
  File root;

 
 root = SD.open("/");
 
  
  

 
  while(true) {

     File entry =  root.openNextFile();
     
     maximo=maximo+1;
     Serial.print(maximo);
    
     if (! entry) {
       // no more files
       Serial.println("**nomorefiles**");
       // return to the first file in the directory
      root.rewindDirectory(); //bring you back to the first file in the directory
      
       break;
     }
     
 } 
 
 
 
 
 
 
 
 
 
 }

ptmir:
want i am doing wrong , my be its not made this lame way.. :slight_smile:

  if (! entry) 
  {
    // no more files
    Serial.println("**nomorefiles**");
    // return to the first file in the directory
    root.rewindDirectory(); //bring you back to the first file in the directory
    break;
  }
  else entry.close();  // do not forget that!

Thanks ! i will try that , sorry i am dyslexic and english is not my mother language hehe :grinning:

THANKS !! its working ! :wink:

void numerofilessdcard() {
 
  File root;

 
 root = SD.open("/");
 
  
  

 
  while(true) {

     File entry =  root.openNextFile();
     
     maximo=maximo+1;
     Serial.print(maximo);
    
      if (! entry) 
  {
    // no more files
    Serial.println("**nomorefiles**");
    // return to the first file in the directory
    root.rewindDirectory(); //bring you back to the first file in the directory
    break;
  }
  else entry.close();  // do not forget that!
     
 } 
 
 
 
 
 
 
 
 
 
 }