Reference.FileIsDirectory History

Hide minor edits - Show changes to output

November 02, 2011, at 02:00 PM by Scott Fitzgerald -
Changed lines 73-74 from:
* [[FileRead | read()]]
* [[FilePeek | peek()]]
to:
* [[Reference/FileOpenNextFile | openNextFile()]]
* [[Reference/FileRewindDirectory | rewindDirectory()]]
November 02, 2011, at 01:56 PM by Scott Fitzgerald -
Changed lines 5-6 from:
Reports if the current file is a directory or not.
to:
Directories (or folders) are special kinds of files, this function reports if the current file is a directory or not.
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:49 PM by Scott Fitzgerald -
Added lines 1-74:
[[SD]] : ''File'' class

!!isDirectory()

Reports if the current file is a directory or not.

!!!!Syntax

''file''.isDirectory()

!!!!Parameters

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

!!!!Returns

boolean

!!!!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:)


!!!!See Also

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

Share