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