Pages: [1]   Go Down
Author Topic: Bug in SD library ?!  (Read 697 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Peoples Republic of Cantabrigia
Offline Offline
God Member
*****
Karma: 6
Posts: 719
Arduino happiness
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1605
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: