Is it posstible to get a file and directory list of SD card faster?
Posted: 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.
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();
}