The f_readdir reads directory items.
FRESULT f_readdir ( DIR* DirObject, // Pointer to the directory object strcture FILINFO* FileInfo // Pointer to the blank file information structure );
The f_readdir reads directory items in sequence. All items in the directory can be read by calling f_readdir repeatedly. When all items have been read and no item to read, the member f_name[] in the file information structure gets a null string. For details of the file informations, refer to the FILINFO.
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.f_name[0]) {
            if (finfo.f_attrib & AM_DIR) {
                sprintf(path+i, "/%s", &finfo.f_name[0]);
                scan_files(path);
                *(path+i) = '\0';
            } else {
                printf("%s/%s\n", path, &finfo.f_name[0]);
            }
        }
    }
}