-
Notifications
You must be signed in to change notification settings - Fork 155
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
SD.exists() has weird side-effects, breaks subsequent SD calls #11
Comments
From @RobTillaart on January 19, 2013 19:29 Discussed on the forum here - https://forum.arduino.cc/t/sd-exists-has-weird-side-effect/139821 |
From @gertrude on January 20, 2013 14:44 ...where the practical answer is, SD.exists() monkeys about with internal state such that subsequent openNextFile() calls fail, unless the caller also remembers to judiciously call rewindDirectory(). I suggest this violates the Principal of Least Surprise: SD.exists() should tidy up after itself, so it doesn't cause later failures in other functions. The results of openNextFile() ideally shouldn't depend on the context within which it was called. |
Has this ever been fixed? I've just run into this same problem. The only difference is that it doesn't matter if I place EDITHmm, what I've noticed is that if I hard-code the filename, all is fine, but if I try to pass in a variable, it freaks out. So: This works:
But this doesn't:
And neither does this:
|
Try this fix: arduino/Arduino#3647 |
@PaulStoffregen I checked the link, but I cannot see how that problem applies here. Thanks for the quick response, though! |
SolutionWeirdly enough, it's the Anyway, this will work just fine:
But will, of course, give you a |
From @blowback on January 17, 2013 13:20
If I take the listfiles.ino example and change the chip select to 4, I can get a directory listing of the contents of my SD card, as expected.
If I modify the code by adding SD.exists("foo);' immediately before the 'root = SD.open("/");' then printDirectory() no longer works - specifically, the first call to dir.openNextFile() fails.
If I move the SD.exists() line to after the SD.open("/") line, then it works again.
I tried wrapping the SD.exists() with its own SD.open().....root.close(), but that caused the directory listing to fail again.
It doesn't matter if the file tested for actually exists or not, the behaviour is the same in both cases (and SD.exists() returns the right result).
Here's the code:
Copied from original issue: arduino/Arduino#1232
The text was updated successfully, but these errors were encountered: