Reference.FileOpenNextFile History

Hide minor edits - Show changes to output

November 06, 2011, at 12:07 AM by Scott Fitzgerald -
Changed lines 51-52 from:
//Serial.println("**nomorefiles**");
break;
to:
Serial.println("**nomorefiles**");
November 02, 2011, at 01:59 PM by Scott Fitzgerald -
Changed lines 73-74 from:
* [[FileRead | read()]]
* [[FilePeek | peek()]]
to:
* [[Reference/FileIsDirectory | isDirectory()]]
* [[Reference/FileRewindDirectory | rewindDirectory()]]
November 02, 2011, at 01:56 PM by Scott Fitzgerald -
Changed lines 13-14 from:
''file'': an instance of the File class (returned by file.[[Reference/SDopen | open()]]
to:
''file'': an instance of the File class that is a directory
November 02, 2011, at 01:50 PM by Scott Fitzgerald -
Changed lines 31-32 from:
SD.begin(10
to:
SD.begin(10);
November 02, 2011, at 01:48 PM by Scott Fitzgerald -
Changed lines 70-72 from:
(:sourceend:)

to:
November 02, 2011, at 01:47 PM by Scott Fitzgerald -
Added lines 1-76:
[[SD]] : ''File'' class

!!openNextFile()

Reports the next file or folder in a directory.

!!!!Syntax

''file''.openNextFile()

!!!!Parameters

''file'': an instance of the File class (returned by file.[[Reference/SDopen | open()]]

!!!!Returns

char : the next file or folder in the path

!!!!Example

(:source lang=arduino:)
#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
//Serial.println("**nomorefiles**");
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);
}
}
}
(:sourceend:)

(:sourceend:)


!!!!See Also

* [[FileRead | read()]]
* [[FilePeek | peek()]]

Share