Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit 2ab3320

Browse files
committed
Fix error when entering empty folder
1 parent 8b6b647 commit 2ab3320

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Cart_Reader/Cart_Reader.ino

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,9 +3528,15 @@ for (byte pass = 0; pass < 2; pass++) {
35283528
#endif
35293529
myDir.close();
35303530

3531-
for (byte i = 0; i < count; i++) {
3531+
if (currFile == 0) {
3532+
// Prevent SD error on empty folder
3533+
count = 1;
3534+
snprintf(answers[0], FILEOPTS_LENGTH, "%s", "Empty folder");
3535+
} else {
35323536
// Copy short string into fileOptions
3533-
snprintf(answers[i], FILEOPTS_LENGTH, "%s", fileNames[i]);
3537+
for (byte i = 0; i < count; i++) {
3538+
snprintf(answers[i], FILEOPTS_LENGTH, "%s", fileNames[i]);
3539+
}
35343540
}
35353541

35363542
// Create menu with title and 1-7 options to choose from
@@ -3542,6 +3548,11 @@ for (byte pass = 0; pass < 2; pass++) {
35423548
goto page;
35433549
}
35443550

3551+
// Setting root after question_box still allows to escape empty folder by scrolling left
3552+
if(strcmp(answers[0], "Empty folder") == 0) {
3553+
root = 1;
3554+
}
3555+
35453556
// Check if we are supposed to go back to the root dir
35463557
if (root) {
35473558
// Change working dir to root

0 commit comments

Comments
 (0)