Go Down

Topic: Bug in SD library ?! (Read 817 times) previous topic - next topic

fs007

I'm new here, but i've a problem with the SD library (arduino 1.0.1., Mega 2560 +SD on Ethernet shield):

I want to dump the directory of an sd card as often as a user want's.
The following code e.g. work's for fine for a few (depends on how much entries exist) loops. Then less directory entries are found, at last even none !
Can anyone help ?
Code: [Select]

#include <SD.h>

  void setup() {
    Serial.begin(9600);
    SD.begin(4);
  }

void loop()   {
            File root = SD.open("/");
            File entry =  root.openNextFile();
            while(entry) {
              Serial.println(entry.name());
              entry =  root.openNextFile();
              }
            root.close();
            Serial.println();
            delay(1000);
}

fs007

OK, found the answer myself:
After each openNextFile is a close() required. Otherwise too many files are obviously left open.

Example in the reference does not show this; perhaps someone could correct this.

Constantin

Good catch. Does the example page list an author? If so, would you mind contacting him/her directly with your good observation? I wouldn't count on them monitoring this forum...

fat16lib

This bug has been around for a long time. 

It is now in the issues list http://code.google.com/p/arduino/issues/detail?id=832&start=300.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy