Reference.FileOpenNextFile History

Hide minor edits - Show changes to output

July 02, 2015, at 09:47 AM by Arturo -
Deleted line 24:
Deleted line 28:
Deleted line 29:
Deleted line 30:
Changed lines 32-33 from:

Serial.println("done!");
to:
delay(2000);
Serial.println();
Serial.println("Rewinding, and repeating below:" );
Serial.println();
delay(2000);
root.rewindDirectory();
printDirectory(root, 0);
root.close();
Changed lines 47-67 from:
void printDirectory(File dir, int numTabs) {
while(true) {

File entry = dir.openNextFile();
if (! entry) {
// no more files
Serial.println("**nomorefiles**");
}
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);
}
}
to:
void printDirectory(File dir, int numTabs)
{
while (true)
{
File entry = dir.openNextFile();
if (! entry)
{
if (numTabs == 0)
Serial.println("** Done **");
return;
}
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
{
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
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