SD.exists/removing files from SD Card

Hello friends.

I try to create a function that will delete all files on my SD card.
I already found some good answers in other posts in this forum but i am still struggling.

I used this function:

void resetlogPopCallback(void *ptr)

char file_Name[12] = {'f','i','l','e','_',0x00,'.','t','x','t'};
   for (int i = 0; i < 100; i++) {
     sprintf(file_Name, "file_%d.txt", i);
     boolean fileFLAG = SD.exists(file_Name);
     if (fileFLAG) {


My problem now is, that “fileFLAG” is never true. So no deletes will be made.

The names of the files on my SD card are following:


… and so on

my Serial.print of the filesnames are:


So they are equal imo. I dont understand whats wrong

Any ideas?

Thank you very much!

Did you call SD.begin() to initialze the card?

The SD card library examples can lead you a bit in the wrong direction if you combine what you learned in each one.

The CardInfo example uses global variables and "low" level functions to extract some card info.
The Files example uses the SD class which does not have the low level functions but file handling.

Try the Files example. Modify the parameter in SD.begin(4) to your chip select pin.

File -> Examples -> SD -> Files