创客百科

姿势共享,有节操无门槛参与的创客百科,创客动力之源 \ (^_^) /

用户工具

站点工具


en:arduino:libraries:filerewinddirectory

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

en:arduino:libraries:filerewinddirectory [2016/12/25 22:15] (当前版本)
行 1: 行 1:
 +[[en:​arduino:​libraries:​sd|SD]] : File class
 +====== rewindDirectory() ======
  
 +
 +rewindDirectory() will bring you back to the first file in the directory, used in conjunction with openNextFile().
 +===== Syntax =====
 +
 +file.rewindDirectory()
 +===== Parameters =====
 +
 +file: an instance of the File class.
 +===== Returns =====
 +
 +None
 +<code cpp>
 +#include <​SD.h>​
 +
 +File root;
 +
 +void setup()
 +{
 +  Serial.begin(9600);​
 +  pinMode(10, OUTPUT);
 +
 +  SD.begin(10);​
 +
 +  root = SD.open("/"​);​
 +
 +  printDirectory(root,​ 0);
 +
 +  Serial.println("​done!"​);​
 +}
 +
 +void loop()
 +{
 +  // nothing happens after setup finishes.
 +}
 +
 +void printDirectory(File dir, int numTabs) {
 +   ​while(true) {
 +
 +     File entry =  dir.openNextFile();​
 +     if (! entry) {
 +       // no more files
 +       // return to the first file in the directory
 +       ​dir.rewindDirectory();​
 +       ​break;​
 +     }
 +     for (uint8_t i=0; i<​numTabs;​ i++) {
 +       ​Serial.print('​\t'​);​
 +     }
 +     ​Serial.print(entry.name());​
 +     if (entry.isDirectory()) {
 +       ​Serial.println("/"​);​
 +       ​printDirectory(entry,​ numTabs+1);
 +     } else {
 +       // files have sizes, directories do not
 +       ​Serial.print("​\t\t"​);​
 +       ​Serial.println(entry.size(),​ DEC);
 +     }
 +   }
 +}
 +</​code> ​
 +
 +===== See Also =====
 +
 +  * open()
 +  * openNextFile()
 +  * isDirectory()
 +[[en:​arduino:​libraries|Reference Home]]
en/arduino/libraries/filerewinddirectory.txt · 最后更改: 2016/12/25 22:15 (外部编辑)