Page 1 of 1

List files store in SPIFFS

Posted: Mon Aug 15, 2022 4:27 pm
by vsfred
Hello,

I would like to list files store in SPIFFS partition. In Arduino world, I do this :

Code: Select all

Dir dir = SPIFFS.openDir("");
while (dir.next()) {
    Serial.print(dir.fileName());
    File f = dir.openFile("r");
    Serial.println(f.size());
}
But with IDF, I don’t known how to list these files.

Re: List files store in SPIFFS

Posted: Mon Aug 15, 2022 11:23 pm
by ESP_igrr
Hi vsfed,

You can use functions opendir, readdir, closedir. Here's a code example. (Assuming you have already mounted the spiffs partition.)

Code: Select all

DIR* dir = opendir("/spiffs/test");
if (dir == NULL) {
    return;
}

while (true) {
    struct dirent* de = readdir(dir);
    if (!de) {
        break;
    }
    
    printf("Found file: %s\n", de->d_name);
}

closedir(dir);

Re: List files store in SPIFFS

Posted: Tue Aug 16, 2022 6:18 am
by vsfred
Hi ESP_igrr,

it works, thank you