]>
Commit | Line | Data |
---|---|---|
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 | |
70702af1 | 16 | <p>The f_readdir function reads an item of the directory.</p>\r |
53668523 L |
17 | <pre>\r |
18 | FRESULT 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 | |
70702af1 | 29 | <dd>Pointer to the open directory object or null pointer.</dd>\r |
53668523 | 30 | <dt>fno</dt>\r |
70702af1 | 31 | <dd>Pointer to the <a href="sfileinfo.html">file information structure</a> to store the information about read item.</dd>\r |
53668523 L |
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 | |
53668523 L |
42 | <a href="rc.html#io">FR_INVALID_OBJECT</a>,\r |
43 | <a href="rc.html#tm">FR_TIMEOUT</a>,\r | |
44 | <a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>\r | |
45 | </p>\r | |
46 | </div>\r | |
47 | \r | |
48 | \r | |
49 | <div class="para desc">\r | |
50 | <h4>Description</h4>\r | |
70702af1 L |
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->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 |
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>\r | |
53668523 | 53 | <ul>\r |
70702af1 L |
54 | <li>The item has no long file name. (Not the case at exFAT volume)</li>\r |
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>\r | |
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>\r | |
53668523 | 57 | </ul>\r |
70702af1 | 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>\r |
53668523 L |
59 | </div>\r |
60 | \r | |
61 | \r | |
62 | <div class="para comp">\r | |
63 | <h4>QuickInfo</h4>\r | |
64 | <p>Available when <tt>_FS_MINIMIZE <= 1</tt>.</p>\r | |
65 | </div>\r | |
66 | \r | |
67 | \r | |
68 | <div class="para use">\r | |
69 | <h4>Sample Code</h4>\r | |
70 | <pre>\r | |
71 | FRESULT scan_files (\r | |
70702af1 | 72 | char* path <span class="c">/* Start node to be scanned (***also used as work area***) */</span>\r |
53668523 L |
73 | )\r |
74 | {\r | |
75 | FRESULT res;\r | |
53668523 | 76 | DIR dir;\r |
70702af1 L |
77 | UINT i;\r |
78 | static FILINFO fno;\r | |
53668523 L |
79 | \r |
80 | \r | |
81 | res = f_opendir(&dir, path); <span class="c">/* Open the directory */</span>\r | |
82 | if (res == FR_OK) {\r | |
53668523 L |
83 | for (;;) {\r |
84 | res = f_readdir(&dir, &fno); <span class="c">/* Read a directory item */</span>\r | |
85 | if (res != FR_OK || fno.fname[0] == 0) break; <span class="c">/* Break on error or end of dir */</span>\r | |
53668523 | 86 | if (fno.fattrib & AM_DIR) { <span class="c">/* It is a directory */</span>\r |
70702af1 L |
87 | i = strlen(path);\r |
88 | sprintf(&path[i], "/%s", fno.fname);\r | |
89 | res = scan_files(path); <span class="c">/* Enter the directory */</span>\r | |
7b78a5a2 | 90 | if (res != FR_OK) break;\r |
70702af1 | 91 | path[i] = 0;\r |
53668523 | 92 | } else { <span class="c">/* It is a file. */</span>\r |
70702af1 | 93 | printf("%s/%s\n", path, fno.fname);\r |
53668523 L |
94 | }\r |
95 | }\r | |
96 | f_closedir(&dir)\r | |
97 | }\r | |
98 | \r | |
99 | return res;\r | |
100 | }\r | |
70702af1 L |
101 | \r |
102 | \r | |
103 | int main (void)\r | |
104 | {\r | |
105 | FATFS fs;\r | |
106 | FRESULT res;\r | |
107 | char buff[256];\r | |
108 | \r | |
109 | \r | |
110 | res = f_mount(&fs, "", 1);\r | |
111 | if (res == FR_OK) {\r | |
112 | strcpy(buff, "/");\r | |
113 | res = scan_files(buff);\r | |
114 | }\r | |
115 | \r | |
116 | return res;\r | |
117 | }\r | |
53668523 L |
118 | </pre>\r |
119 | </div>\r | |
120 | \r | |
121 | \r | |
122 | <div class="para ref">\r | |
123 | <h4>See Also</h4>\r | |
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>\r | |
125 | </div>\r | |
126 | \r | |
127 | <p class="foot"><a href="../00index_e.html">Return</a></p>\r | |
128 | </body>\r | |
129 | </html>\r |