]> cloudbase.mooo.com Git - z180-stamp.git/blame - fatfs/documents/doc/readdir.html
Import fatfs R0.15
[z180-stamp.git] / fatfs / documents / doc / readdir.html
CommitLineData
53668523
L
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\r
2<html lang="en">\r
3<head>\r
289f6a14 4<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\r
53668523
L
5<meta http-equiv="Content-Style-Type" content="text/css">\r
6<link rel="up" title="FatFs" href="../00index_e.html">\r
7<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/readdir.html">\r
8<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">\r
9<title>FatFs - f_readdir</title>\r
10</head>\r
11\r
12<body>\r
13\r
14<div class="para func">\r
15<h2>f_readdir</h2>\r
70702af1 16<p>The f_readdir function reads an item of the directory.</p>\r
53668523
L
17<pre>\r
18FRESULT f_readdir (\r
19 DIR* <span class="arg">dp</span>, <span class="c">/* [IN] Directory object */</span>\r
20 FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] File information structure */</span>\r
21);\r
22</pre>\r
5630b930
L
23<pre>\r
24FRESULT f_rewinddir (\r
25 DIR* <span class="arg">dp</span> <span class="c">/* [IN] Directory object */</span>\r
26);\r
27</pre>\r
53668523
L
28</div>\r
29\r
30<div class="para arg">\r
31<h4>Parameters</h4>\r
32<dl class="par">\r
33<dt>dp</dt>\r
289f6a14 34<dd>Pointer to the open directory object.</dd>\r
53668523 35<dt>fno</dt>\r
289f6a14 36<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>\r
53668523
L
37</dl>\r
38</div>\r
39\r
40\r
41<div class="para ret">\r
42<h4>Return Values</h4>\r
43<p>\r
44<a href="rc.html#ok">FR_OK</a>,\r
45<a href="rc.html#de">FR_DISK_ERR</a>,\r
46<a href="rc.html#ie">FR_INT_ERR</a>,\r
53668523
L
47<a href="rc.html#io">FR_INVALID_OBJECT</a>,\r
48<a href="rc.html#tm">FR_TIMEOUT</a>,\r
49<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>\r
50</p>\r
51</div>\r
52\r
53\r
54<div class="para desc">\r
55<h4>Description</h4>\r
5630b930
L
56<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>\r
57<pre>\r
58#define <em>f_rewinddir</em>(dp) f_readdir((dp), 0)\r
59</pre>\r
60<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>\r
53668523 61<ul>\r
5630b930
L
62<li>The item has no LFN. (Not the case in exFAT volume)</li>\r
63<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>\r
64<li><a href="config.html#lfn_buf"><tt>FF_LFN_BUF</tt></a> is insufficient to store the LFN.</li>\r
65<li>The LFN contains some character not defined in current CP. (Not the case in <tt>FF_LFN_UNICODE != 0</tt>)</li>\r
53668523 66</ul>\r
5630b930
L
67<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>\r
68<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>\r
53668523
L
69</div>\r
70\r
71\r
72<div class="para comp">\r
73<h4>QuickInfo</h4>\r
289f6a14 74<p>Available when <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> &lt;= 1</tt>.</p>\r
53668523
L
75</div>\r
76\r
77\r
78<div class="para use">\r
79<h4>Sample Code</h4>\r
80<pre>\r
81FRESULT scan_files (\r
70702af1 82 char* path <span class="c">/* Start node to be scanned (***also used as work area***) */</span>\r
53668523
L
83)\r
84{\r
85 FRESULT res;\r
53668523 86 DIR dir;\r
70702af1
L
87 UINT i;\r
88 static FILINFO fno;\r
53668523
L
89\r
90\r
91 res = f_opendir(&amp;dir, path); <span class="c">/* Open the directory */</span>\r
92 if (res == FR_OK) {\r
53668523 93 for (;;) {\r
289f6a14 94 res = <em>f_readdir</em>(&amp;dir, &amp;fno); <span class="c">/* Read a directory item */</span>\r
53668523 95 if (res != FR_OK || fno.fname[0] == 0) break; <span class="c">/* Break on error or end of dir */</span>\r
53668523 96 if (fno.fattrib &amp; AM_DIR) { <span class="c">/* It is a directory */</span>\r
70702af1
L
97 i = strlen(path);\r
98 sprintf(&amp;path[i], "/%s", fno.fname);\r
99 res = scan_files(path); <span class="c">/* Enter the directory */</span>\r
7b78a5a2 100 if (res != FR_OK) break;\r
70702af1 101 path[i] = 0;\r
53668523 102 } else { <span class="c">/* It is a file. */</span>\r
70702af1 103 printf("%s/%s\n", path, fno.fname);\r
53668523
L
104 }\r
105 }\r
5630b930 106 f_closedir(&amp;dir);\r
53668523
L
107 }\r
108\r
109 return res;\r
110}\r
70702af1
L
111\r
112\r
113int main (void)\r
114{\r
115 FATFS fs;\r
116 FRESULT res;\r
117 char buff[256];\r
118\r
119\r
120 res = f_mount(&amp;fs, "", 1);\r
121 if (res == FR_OK) {\r
122 strcpy(buff, "/");\r
123 res = scan_files(buff);\r
124 }\r
125\r
126 return res;\r
127}\r
53668523
L
128</pre>\r
129</div>\r
130\r
131\r
132<div class="para ref">\r
133<h4>See Also</h4>\r
134<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>\r
135</div>\r
136\r
137<p class="foot"><a href="../00index_e.html">Return</a></p>\r
138</body>\r
139</html>\r