]> cloudbase.mooo.com Git - z180-stamp.git/blame - fatfs/doc/en/readdir.html
Merge tag 'fatfs-0.10b'
[z180-stamp.git] / fatfs / doc / en / 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
4<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\r
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
16<p>The f_readdir function reads directory entries.</p>\r
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
23</div>\r
24\r
25<div class="para arg">\r
26<h4>Parameters</h4>\r
27<dl class="par">\r
28<dt>dp</dt>\r
29<dd>Pointer to the open directory object.</dd>\r
30<dt>fno</dt>\r
31<dd>Pointer to the file information structure to store the read item.</dd>\r
32</dl>\r
33</div>\r
34\r
35\r
36<div class="para ret">\r
37<h4>Return Values</h4>\r
38<p>\r
39<a href="rc.html#ok">FR_OK</a>,\r
40<a href="rc.html#de">FR_DISK_ERR</a>,\r
41<a href="rc.html#ie">FR_INT_ERR</a>,\r
42<a href="rc.html#nr">FR_NOT_READY</a>,\r
43<a href="rc.html#io">FR_INVALID_OBJECT</a>,\r
44<a href="rc.html#tm">FR_TIMEOUT</a>,\r
45<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>\r
46</p>\r
47</div>\r
48\r
49\r
50<div class="para desc">\r
51<h4>Description</h4>\r
52<p>The <tt>f_readdir()</tt> function reads directory items, file and directory, in sequence. All items in the directory can be read by calling <tt>f_readdir()</tt> function repeatedly. When relative path feature is enabled (<tt>_FS_RPATH &gt;= 1</tt>), dot entries ("." and "..") are not filtered out and they will appear in the read items. When all directory items have been read and no item to read, a null string is returned into the <tt>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>\r
53<p>When LFN feature is enabled, <tt>lfname</tt> and <tt>lfsize</tt> in the file information structure must be initialized with valid value prior to use it. The <tt>lfname</tt> is a pointer to the LFN read buffer. The <tt>lfsize</tt> is size of the LFN read buffer in unit of <tt>TCHAR</tt>. If the LFN is not needed, set a null pointer to the <tt>lfname</tt> and the LFN is not returned. A null string will be returned into the LFN read buffer in case of following conditions.</p>\r
54<ul>\r
55<li>The directory item has no LFN information.</li>\r
56<li>Either the size of read buffer or LFN working buffer is insufficient for the LFN.</li>\r
57<li>The LFN contains any Unicode character that cannot be converted to OEM code. (not the case at Unicode API cfg.)</li>\r
58</ul>\r
59<p>When the directory item has no LFN information, lower case characters can be contained in the <tt>fname[]</tt>.</p>\r
60</div>\r
61\r
62\r
63<div class="para comp">\r
64<h4>QuickInfo</h4>\r
65<p>Available when <tt>_FS_MINIMIZE &lt;= 1</tt>.</p>\r
66</div>\r
67\r
68\r
69<div class="para use">\r
70<h4>Sample Code</h4>\r
71<pre>\r
72FRESULT scan_files (\r
73 char* path <span class="c">/* Start node to be scanned (also used as work area) */</span>\r
74)\r
75{\r
76 FRESULT res;\r
77 FILINFO fno;\r
78 DIR dir;\r
79 int i;\r
80 char *fn; <span class="c">/* This function is assuming non-Unicode cfg. */</span>\r
81<span class="k">#if</span> _USE_LFN\r
82 static char lfn[_MAX_LFN + 1]; <span class="c">/* Buffer to store the LFN */</span>\r
83 fno.lfname = lfn;\r
84 fno.lfsize = sizeof lfn;\r
85<span class="k">#endif</span>\r
86\r
87\r
88 res = f_opendir(&amp;dir, path); <span class="c">/* Open the directory */</span>\r
89 if (res == FR_OK) {\r
90 i = strlen(path);\r
91 for (;;) {\r
92 res = f_readdir(&amp;dir, &amp;fno); <span class="c">/* Read a directory item */</span>\r
93 if (res != FR_OK || fno.fname[0] == 0) break; <span class="c">/* Break on error or end of dir */</span>\r
94 if (fno.fname[0] == '.') continue; <span class="c">/* Ignore dot entry */</span>\r
95<span class="k">#if</span> _USE_LFN\r
96 fn = *fno.lfname ? fno.lfname : fno.fname;\r
97<span class="k">#else</span>\r
98 fn = fno.fname;\r
99<span class="k">#endif</span>\r
100 if (fno.fattrib &amp; AM_DIR) { <span class="c">/* It is a directory */</span>\r
101 sprintf(&amp;path[i], "/%s", fn);\r
102 res = scan_files(path);\r
103 if (res != FR_OK) break;\r
104 path[i] = 0;\r
105 } else { <span class="c">/* It is a file. */</span>\r
106 printf("%s/%s\n", path, fn);\r
107 }\r
108 }\r
109 f_closedir(&amp;dir)\r
110 }\r
111\r
112 return res;\r
113}\r
114</pre>\r
115</div>\r
116\r
117\r
118<div class="para ref">\r
119<h4>See Also</h4>\r
120<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
121</div>\r
122\r
123<p class="foot"><a href="../00index_e.html">Return</a></p>\r
124</body>\r
125</html>\r