Ymodem ESP32 1.0.0
Loading...
Searching...
No Matches
readSpiffs.cpp
Go to the documentation of this file.
1
20#include <Arduino.h>
21#include <SPIFFS.h>
22
23#define MAX_DEBUG
24#define DELETE_FILES
42void setup()
43{
44 // Initialize Serial for debugging
45 Serial.begin(115200);
46 while (!Serial) {
47 ; // Wait until Serial is ready
48 }
49
50 // Initialize SPIFFS
51 if (!SPIFFS.begin(true)) {
52 Serial.println("Error mounting SPIFFS");
53 return;
54 }
55
56 // List files in SPIFFS
57 Serial.println("Files in SPIFFS:");
58 File root = SPIFFS.open("/");
59 File file = root.openNextFile();
60 while (file) {
61 log_v("Name: %s", file.name());
62// Read and display the entire content of the file
63#ifdef MAX_DEBUG
64 Serial.print("Content: ");
65 while (file.available()) {
66 char buffer[101]; // Buffer to store the read characters
67 int bytesRead = file.readBytes(buffer, 100); // Read up to 100 characters
68 buffer[bytesRead] = '\0'; // Ensure the buffer is null-terminated
69 Serial.print(buffer);
70 }
71 Serial.println(); // New line after displaying the file content
72#endif
73 file = root.openNextFile();
74 }
75
76 // Delete all files in SPIFFS
77#ifdef DELETE_FILES
78 root = SPIFFS.open("/");
79 file = root.openNextFile();
80 while (file) {
81 const char* fileName = file.name();
82 if (fileName && strlen(fileName) > 0) {
83 log_w("Deleting file: %s", fileName);
84 if (SPIFFS.remove(fileName)) {
85 log_i("File deleted successfully");
86 }
87 else {
88 log_e("Error deleting file");
89 }
90 }
91 else {
92 log_w("Invalid file name");
93 }
94 file = root.openNextFile();
95 }
96
97 // List files in SPIFFS after deletion
98 Serial.println("Files in SPIFFS after deletion:");
99 root = SPIFFS.open("/");
100 file = root.openNextFile();
101 while (file) {
102 Serial.print("Name: ");
103 Serial.println(file.name());
104 file = root.openNextFile();
105 }
106#endif
107}
108
115void loop()
116{
117 // No code needed in the loop for this operation
118}
void setup()
Setup function for initializing Serial communication and SPIFFS.
void loop()
Main loop function.