documentation of file.rewindDirectory() is ambiguous and confusing
- Dominant language
- Java
- Stars
- 14.6k
- Forks
- 7k
- PR merge metrics
- No merged PRs in 30d
Description
documentation https://www.arduino.cc/en/Reference/FileRewindDirectory of file.rewindDirectory() is ambiguous and confusing:
it actually make not undoubtedly clear for what ist's worth:
original example sketch:
```
#include
File root;
void setup()
{
Serial.begin(9600);
pinMode(10, OUTPUT);
SD.begin(10);
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
}
void loop()
{
// nothing happens after setup finishes.
}
void printDirectory(File dir, int numTabs) {
while(true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
// return to the first file in the directory
dir.rewindDirectory();
break;
}
for (uint8_t i=0; i filelist instead + push()
File SdPath;
volatile int filecount = 0;
//=================================================================
int readDirectory(File dir, int dirLevel) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
// dir.rewindDirectory(); // don't do it! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
break;
}
if(filecount==0) { // <<<<<< NEW
filelist[0]="/";
filecount++;
}
//Serial.print(entry.name());
filelist[filecount] = (String)entry.name();
if (entry.isDirectory()) {
//Serial.println("/");
filelist[filecount] += (String)"/";
//Serial.println(filelist[filecount]);
filecount++;
// <<< no more "/.."
readDirectory(entry, dirLevel + 1);
} else {
// files have sizes, directories do not
//Serial.println(filelist[filecount]);
//Serial.print("\t\t");
//Serial.println(entry.size(), DEC);
filecount++;
}
entry.close();
}
return filecount;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.