SD.remove with esp32

superneyluj
Posts: 4
Joined: Sun Jan 29, 2023 7:05 pm

SD.remove with esp32

Postby superneyluj » 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

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");
    }
  }
But it doesnt work.

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);
}
I dont know what i am doing wrong.

Thanks.

Who is online

Users browsing this forum: No registered users and 59 guests