f_readdir

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
);

Parameters

DirObject
Pointer to the valid directory object strcture.
FileInfo
Pointer to the file information structure to store the read item.

Return Values

FR_OK (0)
The function succeeded.
FR_NOT_READY
The disk drive cannot work due to no medium in the drive or any other reason.
FR_RW_ERROR
Any error occured in low level disk I/O.
FR_NOT_ENABLED
FatFs module is not enabled.

Description

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. This function is not supported in minimization level of 2.

Sample Code

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]);
            }
        }
    }
}

References

f_opendir, f_stat, FILINFO, DIR

Return