Arduino SD Card File Listing Not Showing All Files
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about Arduino SD Card File Listing Not Showing All Files. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
The Problem
SD.openNextFile() does not list all files on the SD card.
Quick Fix
Wrong
File root = SD.open('/');
while (true) {
File f = root.openNextFile();
if (!f) break;
Serial.println(f.name());
}
File listing may miss files or show unexpected names.
Right
#include <SD.h>
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (!entry) break;
for (int i = 0; i < numTabs; i++) Serial.print(" ");
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println('/");
printDirectory(entry, numTabs + 1);
} else {
Serial.print(" ");
Serial.println(entry.size());
}
entry.close();
}
}
void setup() {
Serial.begin(9600);
while (!Serial);
if (!SD.begin(4)) {
Serial.println("SD init failed");
return;
}
File root = SD.open("/');
if (root) {
printDirectory(root, 0);
root.close();
}
}
void loop() { }
SYSTEM~1/
INDEX~1 4096
DATA.TXT 128
LOGS/
LOG001.TXT 256
Prevention
SD library uses 8.3 filenames — long names appear truncated (e.g., SYSTEM~1). Use f.name() for the short name. For recursive listing, the directory must be opened with SD.open(). Close each entry with entry.close(). The root directory is "/".
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro