(Arduino Mega)
Hi,
I want to delete empty files in my SD Card. I use the SdFat library. My script correctly identifies them, but I cant delete them. Above id the full script. The critical lines are at the end.
Thanks for helping.
#include <SPI.h>
#include <SdFat.h>
void setup()
{
SdFat sdCard;
FatVolume *volume;
pinMode(53, OUTPUT);
Serial.begin(115200);
if (sdCard.begin(8, SPI_HALF_SPEED))
Serial.println(F("card found"));
else
{
Serial.println(F("No Card"));
return;
}
volume = sdCard.vol();
if (!volume)
{
Serial.println(F("unreadable card"));
return;
}
File root = sdCard.open("/");
while (true)
{
File entry = root.openNextFile();
if (!entry)
break;
if (entry.size() == 0)
{
// THIS BLOCK SHOWS ME CORRECTLY THE FILES I WANT TO DELETE
char n[20];
entry.getName(n, 20);
Serial.print("delete ");
Serial.print(n);
// THIS LINE DOES NOT WORK. I NEVER GOT THE 'OK'
Serial.println(entry.remove() ? " ok" : " fail");
}
}
// THIS INSTRUCTION CONFIRMS THE FILES ARE STILL THERE
sdCard.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop()
{
Serial.println("Done");
while (1);
}