How to Overwrite SD Card

I'm trying to overwrite on an SD Card using this bit of code:

myFile = SD.open("test.txt", FILE_WRITE | O_TRUNC);

IT's not currently working. I know it has something to do with the "tags". But I haven't been able to find a complete list of the tags and what they do. I'm using the Arduino SD package to read/write. People have pointed out to the documentation, but I'm not really sure where to look. I've found the .h and .cpp files on github (GitHub - arduino-libraries/SD: SD Library for Arduino) But I can only find the O_TRUNC tag in one part of the code and it's not really showing what it does.

I'm basically trying this as a simple way to keep a permanent log of the last "good" reading taken by a sensor. The plan was to keep a simple text file containing the date of the last reading, and overwrite/update each time a new one is taken.

Any advice?

You haven't posted your code, so it is all guesswork.
Did you remember to explicitly close the file before re-opening it?

My question was really about where to find more information on the O_TRUNC and other SD.open() options, so I didn’t really think more code was necessary. This is just some sample code, but I would just like it to overwrite a short string to memory over and over.

/*
  SD card read/write

  This example shows how to read and write data to and from an SD card file
  The circuit:
   SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

  created   Nov 2010
  by David A. Mellis
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

*/

#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(12)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE | O_TRUNC);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

}

void loop() {
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  for (int i = 0; i < 20; i++) {
    Serial.print("--");
    delay(50);
  }
  Serial.print("\n");
}

jbc165:
My question was really about where to find more information on the O_TRUNC and other SD.open() options, so I didn't really think more code was necessary. This is just some sample code, but I would just like it to overwrite a short string to memory over and over.

It surprises me that you would find it difficult to find information on O_TRUNC since, to my knowledge, it has been around for decades and conforms to POSIX.
As to how well a particular implementation of it behaves: you already found the best documentation in the source code of the SD library that you are using.

The full code is almost always better being posted up front, since it provides the most accurate information and also indicates to some extent the ability of the poster, which then can allow for the most appropriate answers.

What is the exact version of the SD library that you are using?
Have you tried with just O_RDWR | O_TRUNC?