The f_readdir function reads directory entries.
FRESULT f_readdir ( DIR* DirObject, /* Pointer to the directory object structure */ FILINFO* FileInfo /* Pointer to the file information structure */ );
The f_readdir function reads directory entries in sequence. All items in the directory can be read by calling f_readdir function repeatedly. When all directory items have been read and no item to read, the function returns a null string into f_name[] member without any error. For details of the file informations, refer to the FILINFO. This function is not supported in minimization level of >=2.
void scan_files (char* path) { FILINFO finfo; DIR dirs; int i; if (f_opendir(&dirs, path) == FR_OK) { i = strlen(path); while ((f_readdir(&dirs, &finfo) == FR_OK) && finfo.fname[0]) { if (finfo.fattrib & AM_DIR) { sprintf(&path[i], "/%s", &finfo.fname[0]); scan_files(path); path[i] = 0; } else { printf("%s/%s\n", path, &finfo.fname[0]); } } } }