SD.remove with esp32
Posted: Sun Feb 26, 2023 9:02 pm
im using an esp32 wrover to take picture and store it in a sd card. this part is working well, but i want to remove all the pictures from the sd card with code so i wrote this in the setup
But it doesnt work.
This is my loop :
I dont know what i am doing wrong.
Thanks.
Code: Select all
root = SD.open("/");
countingFiles(root, 0);
// Now print the total files count
Serial.println(F("fileCountOnSD: "));
Serial.println(fileCountOnSD);
for(int i=1;i<=fileCountOnSD;i++){
String stringToDelete = "picture"+String(i)+".jpg";
if(SD.exists(stringToDelete.c_str())){
SD.remove(stringToDelete.c_str());
}
else{
Serial.println("no file to remove");
}
}
This is my loop :
Code: Select all
void loop() {
//partie caméra
camera_fb_t * fb = NULL;
fb = esp_camera_fb_get();
if(!fb) {
Serial.println("Camera capture failed");
return;
}
else{
Serial.println("Camera capture ok");
fileCountOnSD++;
String path = "/picture" + String(fileCountOnSD) +".jpg";
File file = SD.open(path.c_str(), FILE_WRITE);
if(!file){
Serial.println("Failed to open file in writing mode");
}
else {
file.write(fb->buf, fb->len); // payload (image), payload length
Serial.printf("Saved file to path: %s\n", path.c_str());
}
file.close();
}
esp_camera_fb_return(fb);
delay(10000);
}
Thanks.