-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathESPFileUtils.cpp
More file actions
66 lines (56 loc) · 1.39 KB
/
ESPFileUtils.cpp
File metadata and controls
66 lines (56 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <ESPFileUtils.h>
boolean mountFileSystem() {
if (!LittleFS.begin()) {
Serial.println("LittleFS mount failed");
return false;
}
return true;
}
boolean fileExists(String path) {
Serial.println("Checking if file exists: " + path);
File file = LittleFS.open(path, "r");
if (file) {
Serial.println("file exists: " + path);
file.close();
return true;
}
Serial.println("file not exists: " + path);
return false;
}
String readFile(const String path) {
Serial.println("Reading file: " + path);
String fileContent = "";
File file = LittleFS.open(path, "r");
if (!file) {
Serial.println("Failed to open file for reading");
return fileContent;
}
Serial.print("Read from file: ");
fileContent = file.readString();
Serial.println(fileContent);
file.close();
return fileContent;
}
void writeFile(String path, String message) {
Serial.println("Writing file: " + path);
File file = LittleFS.open(path, "w");
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
if (file.print(message)) {
Serial.println("File written");
} else {
Serial.println("Write failed");
}
file.close();
}
boolean deleteFile(const String path) {
Serial.println("Deleting file: " + path);
if (LittleFS.remove(path)) {
Serial.println("File deleted");
return true;
}
Serial.println("Delete failed");
return false;
}