PlatformIO Community

List directories from SD card

Hello guys, having a problem with listing the directories on my SD card.
While executing the code in Arduino IDE lists me directories in the form of /year/month/day.TXT PlatformIO only lists me the the day.TXT
Any way to get the full path listed in PlatformIO?

#include <Arduino.h>
#include <SD.h>
void printDirectory(File dir, int numTabs);

const int chipSelect = 10;
File root;

void setup() {

  Serial.begin(115200);

  while (!Serial);

  root = SD.open("/");

  printDirectory(root, 0);

}

void loop() {}

void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}

PlatformIO gives:

2021/
        11/
                ._04.TXT                4096
                ._05.TXT                4096
                ._06.TXT                4096
                ._07.TXT                4096
                ._11.TXT                4096
                04.TXT          5126
                05.TXT          897

While Arduino gives:

/2021/
	/2021/11/
		/2021/11/._04.TXT		4096
		/2021/11/._05.TXT		4096
		/2021/11/._06.TXT		4096
		/2021/11/._07.TXT		4096
		/2021/11/._11.TXT		4096
		/2021/11/04.TXT		5126
		/2021/11/05.TXT		897
[env:lolin_d32_pro]
platform = espressif32
board = lolin_d32_pro
framework = arduino
monitor_speed = 115200
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.1
board_build.f_flash = 80000000L

With which Arduino-ESP32 core version is that? (look into the Arduino IDE board manager → esp32 version)

board manager says its esp32 version 1.0.6 by espressif

Then that’s a mismatch. Use

[env:lolin_d32_pro]
platform = espressif32@3.5.0
board = lolin_d32_pro
framework = arduino
monitor_speed = 115200
board_build.f_flash = 80000000L

as your platformio.ini. Is the output different?

That fixed my problem. Thank you alot!

Note that this is actually a downgrade of the Arduino-ESP32 version from what would be 2.0.2 in the latest version to 1.0.6. If you want to work with the latest Arduino core (whose SD library output is apparently different), you’ll have to slightly adapt your sketch to match what the 1.0.6 outputs.

1 Like