2023-12-20 09:19:37 +01:00
|
|
|
#include "FsUtils.h"
|
|
|
|
|
|
|
|
filename_iterator::filename_iterator()
|
|
|
|
: suffix(NULL),
|
|
|
|
valid(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
filename_iterator::filename_iterator(const char* path, const char* suffix)
|
2023-12-20 10:47:26 +01:00
|
|
|
#ifdef ESP8266
|
2023-12-20 09:19:37 +01:00
|
|
|
: dir(LittleFS.openDir(path)),
|
|
|
|
#endif
|
2023-12-20 10:47:26 +01:00
|
|
|
#ifdef ESP32
|
2023-12-20 09:19:37 +01:00
|
|
|
: dir(LittleFS.open(path)),
|
|
|
|
#endif
|
|
|
|
valid(true),
|
|
|
|
suffix(suffix)
|
|
|
|
{
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
filename_iterator::next()
|
|
|
|
{
|
|
|
|
if (!valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int extPos = -1;
|
|
|
|
do {
|
2023-12-20 10:47:26 +01:00
|
|
|
#ifdef ESP8266
|
2023-12-20 09:19:37 +01:00
|
|
|
valid = dir.next();
|
|
|
|
if (valid) {
|
|
|
|
String fname = dir.fileName();
|
|
|
|
extPos = fname.lastIndexOf(suffix);
|
|
|
|
if (extPos != -1) {
|
|
|
|
ret = fname.substring(0, extPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2023-12-20 10:47:26 +01:00
|
|
|
#ifdef ESP32
|
2023-12-20 09:19:37 +01:00
|
|
|
File next = dir.openNextFile();
|
|
|
|
valid = (bool)next;
|
|
|
|
if (valid && !next.isDirectory()) {
|
|
|
|
String fname = next.name();
|
|
|
|
extPos = fname.lastIndexOf(suffix);
|
|
|
|
if (extPos != -1) {
|
|
|
|
ret = fname.substring(0, extPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} while (valid && extPos == -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
filename_iterator& filename_iterator::operator++()
|
|
|
|
{
|
|
|
|
next();
|
|
|
|
return *this;
|
|
|
|
}
|