The pf_readdir function reads directory entries.
FRESULT pf_readdir ( DIR* DirObject, /* Pointer to the open directory object */ FILINFO* FileInfo /* Pointer to the file information structure */ );
The pf_readdir function reads directory entries in sequence. All items in the directory can be read by calling pf_readdir function repeatedly. When all directory entries have been read and no item to read, the function returns a null string into f_name[] member without any error. When a null pointer is given to the FileInfo, the read index of the directory object will be rewinded.
FRESULT scan_files (char* path)
{
FRESULT res;
FILINFO fno;
DIR dir;
int i;
res = pf_opendir(&dir, path);
if (res == FR_OK) {
i = strlen(path);
for (;;) {
res = pf_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0) break;
if (fno.fattrib & AM_DIR) {
sprintf(&path[i], "/%s", fno.fname);
res = scan_files(path);
if (res != FR_OK) break;
path[i] = 0;
} else {
printf("%s/%s\n", path, fno.fname);
}
}
}
return res;
}
Available when _USE_DIR == 1.