class DirIterator { FS& fs; ClusterNr nextCluster; int curEntryInCluster; uint8_t buf[512]; public: DirIterator(FS& fs, ClusterNr clusterNr) : fs(fs), nextCluster(clusterNr), curEntryInCluster(255) { } bool hasNext() { while(true) { ++curEntryInCluster; // reached end of cluster? load the next one if (curEntryInCluster > fs.tmp.dirEntriesPerSector) { fs.dev.read(fs.clusterToAbsPos(nextCluster), 512, buf); nextCluster = fs.getNextCluster(nextCluster); curEntryInCluster = 0; } DirEntry* desc = reinterpret_cast(buf + (sizeof(DirEntry) * curEntryInCluster)); if (desc->isLongFileName()) {continue;} if (desc->isUnused()) {continue;} if (desc->isEndOfDirectory()) {return false;} return true; } } DirEntry next() { DirEntry* de = reinterpret_cast(buf + (sizeof(DirEntry) * curEntryInCluster)); return *de; } };