Is it posstible to get a file and directory list of SD card faster?

Chintiger
Posts: 1
Joined: Wed Aug 11, 2021 10:45 pm

Is it posstible to get a file and directory list of SD card faster?

Postby Chintiger » Sat Aug 14, 2021 1:46 am

Hello,
I use ESP32 WROVER with a simple SPI micro SD card slot.

I have to get a list of all file and direcotory names, I open every entry with openNextFile() and get the file name by entry.name().
But it takes a long time because it opens files one by one.

Is it possible to get file and directory names faster without opening themselvs?

Thank you.

Code: Select all

std::vector<String> dirs;
std::vector<std::vector<String>> files;

  // get direcotry list on the root
  int i=0;
  File dir = SD.open("/");
  while ( 1 ) {
    File entry = dir.openNextFile();
    if (!entry) {
      break;
    }
    if ( entry.isDirectory() ) {
      if ( strncmp(entry.name(), "/System", 7) != 0 ) {
        dirs.push_back(entry.name());
        Serial.println(dirs[i++]);
      }
    }
  }
  dir.close();
 
  // get file names in each direcotry
  files.resize(dirs.size());
  for (i=0; i<dirs.size(); i++){
    dir = SD.open(dirs[i]);
    while(1) {
      File entry = dir.openNextFile();
      if (!entry) break;
      if (!entry.isDirectory()) {
        files[i].push_back(entry.name());
      }
      entry.close();
    }
    dir.close();
  }
  

User avatar
corz.org
Posts: 80
Joined: Fri Feb 03, 2023 10:44 pm
Location: Aberdeen
Contact:

Re: Is it posstible to get a file and directory list of SD card faster?

Postby corz.org » Fri Apr 14, 2023 3:00 am

I would also like to know because f*ck me! Using openNextFile() is way too slow.

Anyone?

Who is online

Users browsing this forum: No registered users and 65 guests