Skip to content

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.
#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

### Why do filenames show as SYSTEM~1?

The Arduino SD library only supports 8.3 short filenames. Long filenames are not supported. Files created on a PC with long names appear in short form.

How do I get the original long filename?

The standard SD library does not support long filenames. Use SdFat library (by Bill Greiman) for long filename (LFN) support.

Can I create subdirectories?

Yes. SD.mkdir("/logs") creates a directory. Open with SD.open("/logs") to list its contents.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro