readdir.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. <body>
  12. <div class="para func">
  13. <h2>f_readdir</h2>
  14. <p>The f_readdir function reads an item of the directory.</p>
  15. <pre>
  16. FRESULT f_readdir (
  17. DIR* <span class="arg">dp</span>, <span class="c">/* [IN] Directory object */</span>
  18. FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] File information structure */</span>
  19. );
  20. </pre>
  21. </div>
  22. <div class="para arg">
  23. <h4>Parameters</h4>
  24. <dl class="par">
  25. <dt>dp</dt>
  26. <dd>Pointer to the open directory object or null pointer.</dd>
  27. <dt>fno</dt>
  28. <dd>Pointer to the <a href="sfileinfo.html">file information structure</a> to store the information about read item.</dd>
  29. </dl>
  30. </div>
  31. <div class="para ret">
  32. <h4>Return Values</h4>
  33. <p>
  34. <a href="rc.html#ok">FR_OK</a>,
  35. <a href="rc.html#de">FR_DISK_ERR</a>,
  36. <a href="rc.html#ie">FR_INT_ERR</a>,
  37. <a href="rc.html#io">FR_INVALID_OBJECT</a>,
  38. <a href="rc.html#tm">FR_TIMEOUT</a>,
  39. <a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
  40. </p>
  41. </div>
  42. <div class="para desc">
  43. <h4>Description</h4>
  44. <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>
  45. <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>
  46. <ul>
  47. <li>The item has no long file name. (Not the case at exFAT volume)</li>
  48. <li>Setting of <tt>_MAX_LFN</tt> is insufficient for the long file name. (Not the case at <tt>_MAX_LFN == 255</tt>)</li>
  49. <li>The long file name contains any character not allowed in ANSI/OEM code. (Not the case at <tt>_LFN_UNICODE == 1</tt>)</li>
  50. </ul>
  51. <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>
  52. </div>
  53. <div class="para comp">
  54. <h4>QuickInfo</h4>
  55. <p>Available when <tt>_FS_MINIMIZE &lt;= 1</tt>.</p>
  56. </div>
  57. <div class="para use">
  58. <h4>Sample Code</h4>
  59. <pre>
  60. FRESULT scan_files (
  61. char* path <span class="c">/* Start node to be scanned (***also used as work area***) */</span>
  62. )
  63. {
  64. FRESULT res;
  65. DIR dir;
  66. UINT i;
  67. static FILINFO fno;
  68. res = f_opendir(&amp;dir, path); <span class="c">/* Open the directory */</span>
  69. if (res == FR_OK) {
  70. for (;;) {
  71. res = f_readdir(&amp;dir, &amp;fno); <span class="c">/* Read a directory item */</span>
  72. if (res != FR_OK || fno.fname[0] == 0) break; <span class="c">/* Break on error or end of dir */</span>
  73. if (fno.fattrib &amp; AM_DIR) { <span class="c">/* It is a directory */</span>
  74. i = strlen(path);
  75. sprintf(&amp;path[i], "/%s", fno.fname);
  76. res = scan_files(path); <span class="c">/* Enter the directory */</span>
  77. if (res != FR_OK) break;
  78. path[i] = 0;
  79. } else { <span class="c">/* It is a file. */</span>
  80. printf("%s/%s\n", path, fno.fname);
  81. }
  82. }
  83. f_closedir(&amp;dir)
  84. }
  85. return res;
  86. }
  87. int main (void)
  88. {
  89. FATFS fs;
  90. FRESULT res;
  91. char buff[256];
  92. res = f_mount(&amp;fs, "", 1);
  93. if (res == FR_OK) {
  94. strcpy(buff, "/");
  95. res = scan_files(buff);
  96. }
  97. return res;
  98. }
  99. </pre>
  100. </div>
  101. <div class="para ref">
  102. <h4>See Also</h4>
  103. <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>
  104. </div>
  105. <p class="foot"><a href="../00index_e.html">Return</a></p>
  106. </body>
  107. </html>