]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - fatfs/doc/en/readdir.html
Merge branch 'chan-fatfs' into fatfs-integration
[z180-stamp.git] / fatfs / doc / en / readdir.html
index bf83ebe619f5ddc49705126f91ad6f332d84c315..235beee7e463de07a2dfe74fad4a7b6ed7947275 100644 (file)
@@ -13,7 +13,7 @@
 \r
 <div class="para func">\r
 <h2>f_readdir</h2>\r
-<p>The f_readdir function reads directory entries.</p>\r
+<p>The f_readdir function reads an item of the directory.</p>\r
 <pre>\r
 FRESULT f_readdir (\r
   DIR* <span class="arg">dp</span>,      <span class="c">/* [IN] Directory object */</span>\r
@@ -26,9 +26,9 @@ FRESULT f_readdir (
 <h4>Parameters</h4>\r
 <dl class="par">\r
 <dt>dp</dt>\r
-<dd>Pointer to the open directory object.</dd>\r
+<dd>Pointer to the open directory object or null pointer.</dd>\r
 <dt>fno</dt>\r
-<dd>Pointer to the file information structure to store the read item.</dd>\r
+<dd>Pointer to the <a href="sfileinfo.html">file information structure</a> to store the information about read item.</dd>\r
 </dl>\r
 </div>\r
 \r
@@ -39,7 +39,6 @@ FRESULT f_readdir (
 <a href="rc.html#ok">FR_OK</a>,\r
 <a href="rc.html#de">FR_DISK_ERR</a>,\r
 <a href="rc.html#ie">FR_INT_ERR</a>,\r
-<a href="rc.html#nr">FR_NOT_READY</a>,\r
 <a href="rc.html#io">FR_INVALID_OBJECT</a>,\r
 <a href="rc.html#tm">FR_TIMEOUT</a>,\r
 <a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>\r
@@ -49,14 +48,14 @@ FRESULT f_readdir (
 \r
 <div class="para desc">\r
 <h4>Description</h4>\r
-<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
-<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
+<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>\r
+<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
 <ul>\r
-<li>The directory item has no LFN information.</li>\r
-<li>Either the size of read buffer or LFN working buffer is insufficient for the LFN.</li>\r
-<li>The LFN contains any Unicode character that cannot be converted to OEM code. (not the case at Unicode API cfg.)</li>\r
+<li>The item has no long file name. (Not the case at exFAT volume)</li>\r
+<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
+<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
 </ul>\r
-<p>When the directory item has no LFN information, lower case characters can be contained in the <tt>fname[]</tt>.</p>\r
+<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
 </div>\r
 \r
 \r
@@ -70,40 +69,28 @@ FRESULT f_readdir (
 <h4>Sample Code</h4>\r
 <pre>\r
 FRESULT scan_files (\r
-    char* path        <span class="c">/* Start node to be scanned (also used as work area) */</span>\r
+    char* path        <span class="c">/* Start node to be scanned (***also used as work area***) */</span>\r
 )\r
 {\r
     FRESULT res;\r
-    FILINFO fno;\r
     DIR dir;\r
-    int i;\r
-    char *fn;   <span class="c">/* This function assumes non-Unicode configuration */</span>\r
-<span class="k">#if</span> _USE_LFN\r
-    static char lfn[_MAX_LFN + 1];   <span class="c">/* Buffer to store the LFN */</span>\r
-    fno.lfname = lfn;\r
-    fno.lfsize = sizeof lfn;\r
-<span class="k">#endif</span>\r
+    UINT i;\r
+    static FILINFO fno;\r
 \r
 \r
     res = f_opendir(&amp;dir, path);                       <span class="c">/* Open the directory */</span>\r
     if (res == FR_OK) {\r
-        i = strlen(path);\r
         for (;;) {\r
             res = f_readdir(&amp;dir, &amp;fno);                   <span class="c">/* Read a directory item */</span>\r
             if (res != FR_OK || fno.fname[0] == 0) break;  <span class="c">/* Break on error or end of dir */</span>\r
-            if (fno.fname[0] == '.') continue;             <span class="c">/* Ignore dot entry */</span>\r
-<span class="k">#if</span> _USE_LFN\r
-            fn = *fno.lfname ? fno.lfname : fno.fname;\r
-<span class="k">#else</span>\r
-            fn = fno.fname;\r
-<span class="k">#endif</span>\r
             if (fno.fattrib &amp; AM_DIR) {                    <span class="c">/* It is a directory */</span>\r
-                sprintf(&amp;path[i], "/%s", fn);\r
-                res = scan_files(path);\r
-                path[i] = 0;\r
+                i = strlen(path);\r
+                sprintf(&amp;path[i], "/%s", fno.fname);\r
+                res = scan_files(path);                    <span class="c">/* Enter the directory */</span>\r
                 if (res != FR_OK) break;\r
+                path[i] = 0;\r
             } else {                                       <span class="c">/* It is a file. */</span>\r
-                printf("%s/%s\n", path, fn);\r
+                printf("%s/%s\n", path, fno.fname);\r
             }\r
         }\r
         f_closedir(&amp;dir)\r
@@ -111,6 +98,23 @@ FRESULT scan_files (
 \r
     return res;\r
 }\r
+\r
+\r
+int main (void)\r
+{\r
+    FATFS fs;\r
+    FRESULT res;\r
+    char buff[256];\r
+\r
+\r
+    res = f_mount(&amp;fs, "", 1);\r
+    if (res == FR_OK) {\r
+        strcpy(buff, "/");\r
+        res = scan_files(buff);\r
+    }\r
+\r
+    return res;\r
+}\r
 </pre>\r
 </div>\r
 \r