findfirst.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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=utf-8">
  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/findfirst.html">
  8. <link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
  9. <title>FatFs - f_findfirst</title>
  10. </head>
  11. <body>
  12. <div class="para func">
  13. <h2>f_findfirst</h2>
  14. <p>The f_findfirst function searches a directroy for an item.</p>
  15. <pre>
  16. FRESULT f_findfirst (
  17. DIR* <span class="arg">dp</span>, <span class="c">/* [OUT] Poninter to the directory object */</span>
  18. FILINFO* <span class="arg">fno</span>, <span class="c">/* [OUT] Pointer to the file information structure */</span>
  19. const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Pointer to the directory name to be opened */</span>
  20. const TCHAR* <span class="arg">pattern</span> <span class="c">/* [IN] Pointer to the matching pattern string */</span>
  21. );
  22. </pre>
  23. </div>
  24. <div class="para arg">
  25. <h4>Parameters</h4>
  26. <dl class="par">
  27. <dt>dp</dt>
  28. <dd>Pointer to the blank directory object.</dd>
  29. <dt>fno</dt>
  30. <dd>Pointer to the file information structure to store the information about the found item.</dd>
  31. <dt>path</dt>
  32. <dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory name</a> to be opened.</dd>
  33. <dt>pattern</dt>
  34. <dd>Pointer to the nul-terminated string that specifies the name matching pattern to be searched for. It is referred by also subsequent <tt>f_findnext</tt> function, so that the string must be valid while the successive function calls.</dd>
  35. </dl>
  36. </div>
  37. <div class="para ret">
  38. <h4>Return Values</h4>
  39. <p>
  40. <a href="rc.html#ok">FR_OK</a>,
  41. <a href="rc.html#de">FR_DISK_ERR</a>,
  42. <a href="rc.html#ie">FR_INT_ERR</a>,
  43. <a href="rc.html#nr">FR_NOT_READY</a>,
  44. <a href="rc.html#np">FR_NO_PATH</a>,
  45. <a href="rc.html#in">FR_INVALID_NAME</a>,
  46. <a href="rc.html#io">FR_INVALID_OBJECT</a>,
  47. <a href="rc.html#id">FR_INVALID_DRIVE</a>,
  48. <a href="rc.html#ne">FR_NOT_ENABLED</a>,
  49. <a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
  50. <a href="rc.html#tm">FR_TIMEOUT</a>,
  51. <a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>,
  52. <a href="rc.html#tf">FR_TOO_MANY_OPEN_FILES</a>
  53. </p>
  54. </div>
  55. <div class="para desc">
  56. <h4>Description</h4>
  57. <p>After the directory specified by <tt class="arg">path</tt> could be opened, it starts to search the directory for items with the name specified by <tt class="arg">pattern</tt>. If the first item is found, the information about the object is stored into the file information structure. For more information about file information structure, refer to <a href="readdir.html"><tt>f_readdir</tt></a> function.</p>
  58. <p>The matching pattern can contain wildcard characters (<tt>?</tt> and <tt>*</tt>). A <tt>?</tt> matches an any character and an <tt>*</tt> matches an any string in length of zero or longer. When support of long file name is enabled, only <tt>fname[]</tt> is tested at <tt>_USE_FIND == 1</tt> and also <tt>altname[]</tt> is tested at <tt>_USE_FIND == 2</tt>. In this revision, there are some differences listed below between FatFs and standard systems in matching condition.</p>
  59. <ul>
  60. <li><tt>"*.*"</tt> never matches any name without extension while it matches any name with or without extension at the standard systems.</li>
  61. <li>Any patterns terminated with a period never matches any name while it matches any name without extensiton at the standard systems.</li>
  62. <li><a href="filename.html#case">DBCS extended characters</a> are compared in case-sensitive at LFN with non-Unicode configuration.</li>
  63. </ul>
  64. </div>
  65. <div class="para comp">
  66. <h4>QuickInfo</h4>
  67. <p>This is a wrapper function of <a href="opendir.html"><tt>f_opendir</tt></a> and <a href="readdir.html"><tt>f_readdir</tt></a> function. Available when <tt>_USE_FIND &gt;= 1</tt> and <tt>_FS_MINIMIZE &lt;= 1</tt>.</p>
  68. </div>
  69. <div class="para use">
  70. <h4>Examples</h4>
  71. <pre>
  72. <span class="c">/* Search a directory for objects and display it */</span>
  73. void find_image (void)
  74. {
  75. FRESULT fr; <span class="c">/* Return value */</span>
  76. DIR dj; <span class="c">/* Directory search object */</span>
  77. FILINFO fno; <span class="c">/* File information */</span>
  78. fr = f_findfirst(&amp;dj, &amp;fno, "", "dsc*.jpg"); <span class="c">/* Start to search for photo files */</span>
  79. while (fr == FR_OK &amp;&amp; fno.fname[0]) { <span class="c">/* Repeat while an item is found */</span>
  80. printf("%s\n", fno.fname); <span class="c">/* Display the object name */</span>
  81. fr = f_findnext(&amp;dj, &amp;fno); <span class="c">/* Search for next item */</span>
  82. }
  83. f_closedir(&amp;dj);
  84. }
  85. </pre>
  86. </div>
  87. <div class="para ref">
  88. <h4>See Also</h4>
  89. <p><tt><a href="findnext.html">f_findnext</a>, <a href="closedir.html">f_closedir</a>, <a href="sdir.html">DIR</a>, <a href="sfileinfo.html">FILINFO</a></tt></p>
  90. </div>
  91. <p class="foot"><a href="../00index_e.html">Return</a></p>
  92. </body>
  93. </html>