## f_readdir

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

#### Parameters

DirObject
  Pointer to the open directory 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
  The function failed due to a disk error or an internal error.
FR_INVALID_OBJECT
  The directory object is invalid.

#### Description

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.

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

#### References

`f_opendir, f_stat, FILINFO, DIR`

Return