List files store in SPIFFS

vsfred
Posts: 9
Joined: Mon Aug 15, 2022 12:12 pm

List files store in SPIFFS

Postby vsfred » Mon Aug 15, 2022 4:27 pm

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.

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: List files store in SPIFFS

Postby ESP_igrr » Mon Aug 15, 2022 11:23 pm

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);

vsfred
Posts: 9
Joined: Mon Aug 15, 2022 12:12 pm

Re: List files store in SPIFFS

Postby vsfred » Tue Aug 16, 2022 6:18 am

Hi ESP_igrr,

it works, thank you

Who is online

Users browsing this forum: awegel and 111 guests