Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make File::rewindDirectory reference demo code more clear #118

Merged
merged 2 commits into from
Apr 25, 2022
Merged

Make File::rewindDirectory reference demo code more clear #118

merged 2 commits into from
Apr 25, 2022

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Apr 24, 2022

The reference page for File::rewindDirectory provides a sketch demonstrating its usage.

Feedback was received that the code did not clearly demonstrate the use and effect of the function: arduino/Arduino#11734

@PaulStoffregen suggested several changes to improve on that situation. An atomic subset of those are proposed here:

  • Avoid unnecessary calls of File::rewindDirectory: 615568f
  • Print the card file structure twice: 55cd20f

Resolves (partially) arduino/Arduino#11734

per1234 added 2 commits April 25, 2022 02:08
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
`File::rewindDirectory` is used to reset the current position in the file system. Previously, the file structure was
only iterated over once, in which case rewinding is not necessary and will have no observable effect.

In the following sequence, it is necessary and does have an observable effect:

1. Iterate over file structure using `File::openNextFile`
2. Reset current position using `File::rewindDirectory`
3. Iterate over file structure using `File::openNextFile`

The reader can simply remove the `File::rewindDirectory` call from the program that follows this sequence for a clear
demonstration of its purpose.
@per1234 per1234 merged commit d4ed450 into arduino-libraries:master Apr 25, 2022
@per1234 per1234 deleted the improve-rewinddirectory-ref-code branch April 25, 2022 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: documentation Related to documentation for the project type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants