1e6865dcdSopenharmony_ci<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2e6865dcdSopenharmony_ci<html lang="en">
3e6865dcdSopenharmony_ci<head>
4e6865dcdSopenharmony_ci<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5e6865dcdSopenharmony_ci<meta http-equiv="Content-Style-Type" content="text/css">
6e6865dcdSopenharmony_ci<link rel="up" title="FatFs" href="../00index_e.html">
7e6865dcdSopenharmony_ci<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/readdir.html">
8e6865dcdSopenharmony_ci<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
9e6865dcdSopenharmony_ci<title>FatFs - f_readdir</title>
10e6865dcdSopenharmony_ci</head>
11e6865dcdSopenharmony_ci
12e6865dcdSopenharmony_ci<body>
13e6865dcdSopenharmony_ci
14e6865dcdSopenharmony_ci<div class="para func">
15e6865dcdSopenharmony_ci<h2>f_readdir</h2>
16e6865dcdSopenharmony_ci<p>The f_readdir function reads an item of the directory.</p>
17e6865dcdSopenharmony_ci<pre>
18e6865dcdSopenharmony_ciFRESULT f_readdir (
19e6865dcdSopenharmony_ci  DIR* <span class="arg">dp</span>,      <span class="c">/* [IN] Directory object */</span>
20e6865dcdSopenharmony_ci  FILINFO* <span class="arg">fno</span>  <span class="c">/* [OUT] File information structure */</span>
21e6865dcdSopenharmony_ci);
22e6865dcdSopenharmony_ci</pre>
23e6865dcdSopenharmony_ci<pre>
24e6865dcdSopenharmony_ciFRESULT f_rewinddir (
25e6865dcdSopenharmony_ci  DIR* <span class="arg">dp</span>       <span class="c">/* [IN] Directory object */</span>
26e6865dcdSopenharmony_ci);
27e6865dcdSopenharmony_ci</pre>
28e6865dcdSopenharmony_ci</div>
29e6865dcdSopenharmony_ci
30e6865dcdSopenharmony_ci<div class="para arg">
31e6865dcdSopenharmony_ci<h4>Parameters</h4>
32e6865dcdSopenharmony_ci<dl class="par">
33e6865dcdSopenharmony_ci<dt>dp</dt>
34e6865dcdSopenharmony_ci<dd>Pointer to the open directory object.</dd>
35e6865dcdSopenharmony_ci<dt>fno</dt>
36e6865dcdSopenharmony_ci<dd>Pointer to the <a href="sfileinfo.html">file information structure</a> to store the information about read item. A null pointer rewinds the read index of the directory.</dd>
37e6865dcdSopenharmony_ci</dl>
38e6865dcdSopenharmony_ci</div>
39e6865dcdSopenharmony_ci
40e6865dcdSopenharmony_ci
41e6865dcdSopenharmony_ci<div class="para ret">
42e6865dcdSopenharmony_ci<h4>Return Values</h4>
43e6865dcdSopenharmony_ci<p>
44e6865dcdSopenharmony_ci<a href="rc.html#ok">FR_OK</a>,
45e6865dcdSopenharmony_ci<a href="rc.html#de">FR_DISK_ERR</a>,
46e6865dcdSopenharmony_ci<a href="rc.html#ie">FR_INT_ERR</a>,
47e6865dcdSopenharmony_ci<a href="rc.html#io">FR_INVALID_OBJECT</a>,
48e6865dcdSopenharmony_ci<a href="rc.html#tm">FR_TIMEOUT</a>,
49e6865dcdSopenharmony_ci<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
50e6865dcdSopenharmony_ci</p>
51e6865dcdSopenharmony_ci</div>
52e6865dcdSopenharmony_ci
53e6865dcdSopenharmony_ci
54e6865dcdSopenharmony_ci<div class="para desc">
55e6865dcdSopenharmony_ci<h4>Description</h4>
56e6865dcdSopenharmony_ci<p>The <tt>f_readdir</tt> function reads a directory item, informations about the object, from the open directory. Items in the directory can be read in sequence by <tt>f_readdir</tt> function calls. When all items in the directory have been read and no item to read, a null string is stored into the <tt>fno-&gt;fname[]</tt> without any error. When a null pointer is given to the <tt class="arg">fno</tt>, the read index of the directory object is rewinded. The <tt>f_rewinddir</tt> function is implemented as a macro.</p>
57e6865dcdSopenharmony_ci<pre>
58e6865dcdSopenharmony_ci#define <em>f_rewinddir</em>(dp) f_readdir((dp), 0)
59e6865dcdSopenharmony_ci</pre>
60e6865dcdSopenharmony_ci<p>When LFN is enabled, a member <tt>altname[]</tt> is defined in the file information structure to store the short file name of the object. If the long file name is not accessible due to a reason listed below, short file name is stored to the <tt>fname[]</tt> and the <tt>altname[]</tt> has a null string.</p>
61e6865dcdSopenharmony_ci<ul>
62e6865dcdSopenharmony_ci<li>The item has no LFN. (Not the case in exFAT volume)</li>
63e6865dcdSopenharmony_ci<li><a href="config.html#max_lfn"><tt>FF_MAX_LFN</tt></a> is insufficient to handle the LFN. (Not the case in <tt>FF_MAX_LFN == 255</tt>)</li>
64e6865dcdSopenharmony_ci<li><a href="config.html#lfn_buf"><tt>FF_LFN_BUF</tt></a> is insufficient to store the LFN.</li>
65e6865dcdSopenharmony_ci<li>The LFN contains some character not defined in current CP. (Not the case in <tt>FF_LFN_UNICODE != 0</tt>)</li>
66e6865dcdSopenharmony_ci</ul>
67e6865dcdSopenharmony_ci<p>There is an issue on read directories in exFAT volume. The exFAT does not support short file name. This means no name can be returned on the condition above. If it is the case, "?" is returned as the file name to indicate that the object is not accessible. To avoid this problem, configure FatFs <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> != 0</tt> and <tt>FF_MAX_LFN == 255</tt> to support the full feature of LFN specification.</p>
68e6865dcdSopenharmony_ci<p>Dot entries (<tt>"."</tt> and <tt>".."</tt>) in the sub-directory of FAT volume are filtered out and they will never appear in the read items because exFAT lacks dot entries in the sub-directory.</p>
69e6865dcdSopenharmony_ci</div>
70e6865dcdSopenharmony_ci
71e6865dcdSopenharmony_ci
72e6865dcdSopenharmony_ci<div class="para comp">
73e6865dcdSopenharmony_ci<h4>QuickInfo</h4>
74e6865dcdSopenharmony_ci<p>Available when <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> &lt;= 1</tt>.</p>
75e6865dcdSopenharmony_ci</div>
76e6865dcdSopenharmony_ci
77e6865dcdSopenharmony_ci
78e6865dcdSopenharmony_ci<div class="para use">
79e6865dcdSopenharmony_ci<h4>Sample Code</h4>
80e6865dcdSopenharmony_ci<pre>
81e6865dcdSopenharmony_ciFRESULT scan_files (
82e6865dcdSopenharmony_ci    char* path        <span class="c">/* Start node to be scanned (***also used as work area***) */</span>
83e6865dcdSopenharmony_ci)
84e6865dcdSopenharmony_ci{
85e6865dcdSopenharmony_ci    FRESULT res;
86e6865dcdSopenharmony_ci    DIR dir;
87e6865dcdSopenharmony_ci    UINT i;
88e6865dcdSopenharmony_ci    static FILINFO fno;
89e6865dcdSopenharmony_ci
90e6865dcdSopenharmony_ci
91e6865dcdSopenharmony_ci    res = f_opendir(&amp;dir, path);                       <span class="c">/* Open the directory */</span>
92e6865dcdSopenharmony_ci    if (res == FR_OK) {
93e6865dcdSopenharmony_ci        for (;;) {
94e6865dcdSopenharmony_ci            res = <em>f_readdir</em>(&amp;dir, &amp;fno);                   <span class="c">/* Read a directory item */</span>
95e6865dcdSopenharmony_ci            if (res != FR_OK || fno.fname[0] == 0) break;  <span class="c">/* Break on error or end of dir */</span>
96e6865dcdSopenharmony_ci            if (fno.fattrib &amp; AM_DIR) {                    <span class="c">/* It is a directory */</span>
97e6865dcdSopenharmony_ci                i = strlen(path);
98e6865dcdSopenharmony_ci                sprintf(&amp;path[i], "/%s", fno.fname);
99e6865dcdSopenharmony_ci                res = scan_files(path);                    <span class="c">/* Enter the directory */</span>
100e6865dcdSopenharmony_ci                if (res != FR_OK) break;
101e6865dcdSopenharmony_ci                path[i] = 0;
102e6865dcdSopenharmony_ci            } else {                                       <span class="c">/* It is a file. */</span>
103e6865dcdSopenharmony_ci                printf("%s/%s\n", path, fno.fname);
104e6865dcdSopenharmony_ci            }
105e6865dcdSopenharmony_ci        }
106e6865dcdSopenharmony_ci        f_closedir(&amp;dir);
107e6865dcdSopenharmony_ci    }
108e6865dcdSopenharmony_ci
109e6865dcdSopenharmony_ci    return res;
110e6865dcdSopenharmony_ci}
111e6865dcdSopenharmony_ci
112e6865dcdSopenharmony_ci
113e6865dcdSopenharmony_ciint main (void)
114e6865dcdSopenharmony_ci{
115e6865dcdSopenharmony_ci    FATFS fs;
116e6865dcdSopenharmony_ci    FRESULT res;
117e6865dcdSopenharmony_ci    char buff[256];
118e6865dcdSopenharmony_ci
119e6865dcdSopenharmony_ci
120e6865dcdSopenharmony_ci    res = f_mount(&amp;fs, "", 1);
121e6865dcdSopenharmony_ci    if (res == FR_OK) {
122e6865dcdSopenharmony_ci        strcpy(buff, "/");
123e6865dcdSopenharmony_ci        res = scan_files(buff);
124e6865dcdSopenharmony_ci    }
125e6865dcdSopenharmony_ci
126e6865dcdSopenharmony_ci    return res;
127e6865dcdSopenharmony_ci}
128e6865dcdSopenharmony_ci</pre>
129e6865dcdSopenharmony_ci</div>
130e6865dcdSopenharmony_ci
131e6865dcdSopenharmony_ci
132e6865dcdSopenharmony_ci<div class="para ref">
133e6865dcdSopenharmony_ci<h4>See Also</h4>
134e6865dcdSopenharmony_ci<p><tt><a href="opendir.html">f_opendir</a>, <a href="closedir.html">f_closedir</a>, <a href="stat.html">f_stat</a>, <a href="sfileinfo.html">FILINFO</a>, <a href="sdir.html">DIR</a></tt></p>
135e6865dcdSopenharmony_ci</div>
136e6865dcdSopenharmony_ci
137e6865dcdSopenharmony_ci<p class="foot"><a href="../00index_e.html">Return</a></p>
138e6865dcdSopenharmony_ci</body>
139e6865dcdSopenharmony_ci</html>
140