mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
функции списка файлов от Сереги Третьякова
This commit is contained in:
@@ -16,3 +16,5 @@ void cleanDirectory(String path);
|
||||
void saveDataDB(String id, String data);
|
||||
String readDataDB(String id);
|
||||
extern void onFlashWrite();
|
||||
|
||||
String FileList(String path);
|
||||
24
src/Main.cpp
24
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---------");
|
||||
|
||||
|
||||
@@ -216,3 +216,48 @@ void onFlashWrite() {
|
||||
flashWriteNumber++;
|
||||
// SerialPrint(F("->"), F("FS"), F("write data on flash"));
|
||||
}
|
||||
|
||||
// Создаем список файлов каталога, функции от Сергея Третьякова
|
||||
#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
|
||||
Reference in New Issue
Block a user