0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ESP32: SPIFFS のファイルのリスト

Last updated at Posted at 2024-08-05

ファイル -> スケッチ例 -> SPIFFS -> SPIFFS_Test を参考にしました。

image.png

Ubuntu 24.04 だとコードは次の場所にあります。

.platformio/packages/framework-arduinoespressif32/libraries/SPIFFS/examples/SPIFFS_Test

プログラム

SPIFFS_List.ino
// ---------------------------------------------------------------------
/*
	SPIFFS_List.ino

						Aug/05/2024
*/
// ---------------------------------------------------------------------
#include "FS.h"
#include "SPIFFS.h"

#define FORMAT_SPIFFS_IF_FAILED true

// ---------------------------------------------------------------------
void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
	Serial.printf("Listing directory: %s\r\n", dirname);

	File root = fs.open(dirname);
	if (!root) {
		Serial.println("- failed to open directory");
		return;
	}
	if (!root.isDirectory()) {
		Serial.println(" - not a directory");
		return;
	}

	File file = root.openNextFile();
	while (file) {
		if (file.isDirectory()) {
			Serial.print("	DIR : ");
			Serial.println(file.name());
			if (levels) {
				listDir(fs, file.path(), levels - 1);
			}
		} else {
			Serial.print("	FILE: ");
			Serial.print(file.name());
			Serial.print("\tSIZE: ");
			Serial.println(file.size());
		}
		file = root.openNextFile();
	}
}

// ---------------------------------------------------------------------
void setup() {
	Serial.begin(115200);
	if (!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)) {
		Serial.println("SPIFFS Mount Failed");
		return;
	}

	listDir(SPIFFS, "/", 0);

	Serial.println("Test complete");
}

// ---------------------------------------------------------------------
void loop() {}
// ---------------------------------------------------------------------
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?