## pf_readdir

The pf_readdir function reads directory entries.

    FRESULT pf_readdir (
      DIR* dp,      /* [IN]  Pointer to the open directory object */
      FILINFO* fno  /* [OUT] Pointer to the file information structure */
    );

#### Parameters

dp
  Pointer to the open directory object.
fno
  Pointer to the file information structure to store the read item.

#### Return Values

FR_OK (0)
  The function succeeded.
FR_DISK_ERR
  The function failed due to an error in the disk function, a wrong FAT structure or an internal error.
FR_NOT_OPENED
  The directory object has not been opened.

#### Description

The `pf_readdir()` function reads directory entries in sequence. All items in the directory can be read by calling this function repeatedly. When all directory entries have been read and no item to read, the function returns a null string into member `f_name[]` in the file information structure without error. When a null pointer is given to the `fno`, the read index of the directory object will be rewinded.

#### Sample Code

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

#### QuickInfo

Available when `_USE_DIR == 1`.

#### References

`pf_opendir, FILINFO, DIR`

Return