Skip to content

Commit 615568f

Browse files
committed
Avoid unnecessary calls in rewindDirectory reference code
The reference page for `File::rewindDirectory` provides a sketch demonstrating its usage. This code calls the function after iterating over each directory on the card. This would be necessary if the `printDirectory` function was configured to iterate over that directory multiple times, but it is not. So the calls are redundant. Moving the call to the `setup` function has the following benefits: - Makes the use of the function more prominent. The reader can get an overview of what the program is doing without delving into the `printDirectory` function - Avoids the misconception that it is required to call the function recursively as was done before
1 parent aa96633 commit 615568f

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

docs/api.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ void setup() {
833833
SD.begin(10);
834834
root = SD.open("/");
835835
printDirectory(root, 0);
836+
root.rewindDirectory(); // Return to the first file in the directory
836837
Serial.println("Done!");
837838
}
838839
@@ -845,8 +846,6 @@ void printDirectory(File dir, int numTabs) {
845846
File entry = dir.openNextFile();
846847
if (! entry) {
847848
// No more files
848-
// Return to the first file in the directory
849-
dir.rewindDirectory();
850849
break;
851850
}
852851

0 commit comments

Comments
 (0)