From 8785143bff5166d1913c95b754eb1d1a6162fc3d Mon Sep 17 00:00:00 2001 From: Develo Date: Mon, 29 Oct 2018 14:53:50 -0300 Subject: [PATCH] Fix/update doc for dir object (#5291) * Fix arg type in Wire to size_t * Document dir.fileSize() and other nearby doc fixes --- doc/filesystem.rst | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/doc/filesystem.rst b/doc/filesystem.rst index 3e6fdeffb..606a2707d 100644 --- a/doc/filesystem.rst +++ b/doc/filesystem.rst @@ -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: @@ -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 +~~~~ -``openFile`` method takes *mode* argument which has the same meaning as -for ``SPIFFS.open`` function. +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 +~~~~~~~~ + +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.