140 auto fs = get_fatfs();
148 if (!push_directory(rootPath.empty() ?
"/" : rootPath)) {
157 while (!stack.empty()) {
171 return end_flag != other.end_flag;
184 bool push_directory(
const std::string& path) {
185 if (!fs)
return false;
189 FRESULT res = fs->
f_opendir(&level.dir, path.c_str());
191 stack.push_back(level);
198 if (!fs || stack.empty()) {
205 while (!stack.empty()) {
206 auto& level = stack.back();
209 FRESULT res = fs->
f_readdir(&level.dir, &info);
211 if (res != FR_OK || info.fname[0] == 0) {
219 if (strcmp(info.fname,
".") == 0 || strcmp(info.fname,
"..") == 0) {
224 current_entry.path = level.path;
225 if (!current_entry.path.empty() && current_entry.path.back() !=
'/') {
226 current_entry.path +=
"/";
228 current_entry.path += info.fname;
229 current_entry.is_directory = (info.fattrib & AM_DIR) != 0;
230 current_entry.size = info.fsize;
234 if (current_entry.is_directory) {
235 push_directory(current_entry.path);
247 std::vector<DirLevel> stack;
Representation of a directory entry.
Definition filesystem.h:18