Skip to content

Fix/update doc for dir object #5291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions doc/filesystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Directory object (Dir)
----------------------

The purpose of *Dir* object is to iterate over files inside a directory.
It provides three methods: ``next()``, ``fileName()``, and
It provides the methods: ``next()``, ``fileName()``, ``fileSize()`` , and
``openFile(mode)``.

The following example shows how it should be used:
Expand All @@ -288,21 +288,41 @@ The following example shows how it should be used:
Dir dir = SPIFFS.openDir("/data");
while (dir.next()) {
Serial.print(dir.fileName());
File f = dir.openFile("r");
Serial.println(f.size());
if(dir.fileSize()) {
File f = dir.openFile("r");
Serial.println(f.size());
}
}

``dir.next()`` returns true while there are files in the directory to
iterate over. It must be called before calling ``fileName`` and
``openFile`` functions.
next
~~~~

Returns true while there are files in the directory to
iterate over. It must be called before calling ``fileName()``, ``fileSize()``,
and ``openFile()`` functions.

fileName
~~~~~~~~~

Returns the name of the current file pointed to
by the internal iterator.

fileSize
~~~~~~~~

Returns the size of the current file pointed to
by the internal iterator.

openFile
~~~~~~~~

``openFile`` method takes *mode* argument which has the same meaning as
for ``SPIFFS.open`` function.
This method takes *mode* argument which has the same meaning as
for ``SPIFFS.open()`` function.

File object
-----------

``SPIFFS.open`` and ``dir.openFile`` functions return a *File* object.
``SPIFFS.open()`` and ``dir.openFile()`` functions return a *File* object.
This object supports all the functions of *Stream*, so you can use
``readBytes``, ``findUntil``, ``parseInt``, ``println``, and all other
*Stream* methods.
Expand Down