Running Arduine IDE SD DataLogger Example, my data gets appended to a txt file.

File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {

Is there an explicit option to open the file in overwrite / append modes?

  • thanks for the edit @michael – tony gil Feb 24 '20 at 21:38

If you look in this library, you see:

File SDClass::open(const char *filepath, uint8_t mode) {


    if ((mode & (O_APPEND | O_WRITE)) == (O_APPEND | O_WRITE)) {

So you can use all these mode combinations (e.g. O_CREATE, O_APPEND, O_WRITE).

  • 1
    answered the question as asked. UPVOTED & ACCEPTED :) – tony gil Feb 24 '20 at 21:39

You only need to open the file with FILE_WRITE and use file.seek(EOF) to go to de end of the file. After that you can write whatever you want that will be appended to the end of the file.

File outputFile = SD.open(LOG_FILE, FILE_WRITE);
outputFile.println("Appended to the EOF");
  • perfect for day-to-day solutions, thanks! UPVOTED – tony gil Feb 24 '20 at 21:37

The Arduino SD library is an Arduino wrapper of old version of SdFat library (put into utility subfolder of the SD library). This SdFat library has constants like O_READ, O_WRITE, O_APPEND.

Arduino wrapper has constants


You can use the SdFa library constants in the wrapper calls.

File dataFile = SD.open("datalog.txt", O_READ | O_WRITE | O_CREAT);

Warning: not all versions of SD library bundled in different board packages have O_APPEND in #define FILE_WRITE. Even in the Arduino SD library the O_APPEND was removed some time ago and then the change was reverted, because all dataloger examples used FILE_WRITE.

  • nice solution thanks! UPVOTED – tony gil Feb 24 '20 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.