diff --git a/include/utils/FileUtils.h b/include/utils/FileUtils.h index 1c4e8918..6a528fe6 100644 --- a/include/utils/FileUtils.h +++ b/include/utils/FileUtils.h @@ -15,4 +15,6 @@ void removeFile(const String& filename); void cleanDirectory(String path); void saveDataDB(String id, String data); String readDataDB(String id); -extern void onFlashWrite(); \ No newline at end of file +extern void onFlashWrite(); + +String FileList(String path); \ No newline at end of file diff --git a/src/Main.cpp b/src/Main.cpp index 472b4499..437a4f6f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -73,17 +73,19 @@ void setup() { Serial.println("-------test start--------"); //=======проверка очереди из структур================= - myDB = new IoTDB; - QueueItems myItem; - myItem.myword = "word1"; - myDB->push(myItem); - myItem.myword = "word2"; - myDB->push(myItem); - myItem.myword = "word3"; - myDB->push(myItem); - Serial.println(myDB->front().myword); - Serial.println(myDB->front().myword); - Serial.println(myDB->front().myword); + // myDB = new IoTDB; + // QueueItems myItem; + // myItem.myword = "word1"; + // myDB->push(myItem); + // myItem.myword = "word2"; + // myDB->push(myItem); + // myItem.myword = "word3"; + // myDB->push(myItem); + // Serial.println(myDB->front().myword); + // Serial.println(myDB->front().myword); + // Serial.println(myDB->front().myword); + + Serial.println(FileList("lg")); Serial.println("--------test end---------"); diff --git a/src/utils/FileUtils.cpp b/src/utils/FileUtils.cpp index d6076261..dfdfa4f7 100644 --- a/src/utils/FileUtils.cpp +++ b/src/utils/FileUtils.cpp @@ -215,4 +215,49 @@ String readDataDB(String id) { void onFlashWrite() { flashWriteNumber++; // SerialPrint(F("->"), F("FS"), F("write data on flash")); -} \ No newline at end of file +} + +// Создаем список файлов каталога, функции от Сергея Третьякова +#if defined(ESP8266) +String FileList(String path) { + Dir dir = FileFS.openDir(path); + path = String(); + String output = "["; + while (dir.next()) { + File entry = dir.openFile("r"); + if (output != "[") output += ','; + bool isDir = false; + output += "{\"type\":\""; + output += (isDir) ? "dir" : "file"; + output += "\",\"name\":\""; + output += String(entry.name()).substring(1); + output += "\"}"; + entry.close(); + } + output += "]"; + return output; +} +#else +String FileList(String path) { + File root = FileFS.open(path); + path = String(); + + String output = "["; + if (root.isDirectory()) { + File file = root.openNextFile(); + while (file) { + if (output != "[") { + output += ','; + } + output += "{\"type\":\""; + output += (file.isDirectory()) ? "dir" : "file"; + output += "\",\"name\":\""; + output += String(file.path()).substring(1); + output += "\"}"; + file = root.openNextFile(); + } + } + output += "]"; + return output; +} +#endif \ No newline at end of file