SD card writing issue

Hello all,

I'd like to ask for help regarding an issue I'm having with SD card writing.

I'm writing 10 headings for each column with tabs ("\t") between them - such that after importing into excel via text file with tab delimited all headings sit correctly (one column for each).

The second line will be used for printing variable values when one of them change its value, and I want the first line to be always there.

I tried used SD.write and SD.append functions but the first one clears all data on the first line, second one add one line for each time that function is called in the code.

How can I adapt easily the functions to suit my needs?
Also any way to just change the specific column (each data variable) if for instance only one variable change and the others remain constant? Or better to write all of them as soon as one of them change?

I'm using a string for concatenate all the variables and all the headings, and then:

String headings = "Date\tHour\tCountry\tAge........

writeFile(SD, "/data.txt",headings.c_str());

writeFile(SD, "/data.txt",variables.c_str());

Functions below:

void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Writing file: %s\r\n", path);

File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("- failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("- file written");
} else {
Serial.println("- frite failed");
}
}

void appendFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Appending to file: %s\r\n", path);

File file = fs.open(path, FILE_APPEND);
if(!file){
Serial.println("- failed to open file for appending");
return;
}
if(file.print(message)){
Serial.println("- message appended");
} else {
Serial.println("- append failed");
}
}

Many thanks!

which library?

Thanks for the reply.
It is this one... arduino-esp32/SPIFFS_Test.ino at master · espressif/arduino-esp32 · GitHub

SPIFFS is not for SD card. it is for internal flash memory file system

Thanks for pointing that out, I'll look into others libraries...