Remove file with "SdFat.h"

Hi guys,

I'm using a Arduino DUE with a CTE TFT shield, which has a SD slot.
I tried the code above, with the modification proposed by fat16lib, just calling myFile.remove() at the end.
I also changed the value of chipSelect to 53, since I'm using a DUE.

// Ported to SdFat from the native Arduino SD library example by Bill Greiman
// On the Ethernet Shield, CS is pin 4. SdFat handles setting SS
const uint8_t chipSelect = 53;
/*
 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
 
 created   Nov 2010
 by David A. Mellis
 updated 2 Dec 2010
 by Tom Igoe
 modified by Bill Greiman 11 Apr 2011
 This example code is in the public domain.
 	 
 */
#include <SdFat.h>
SdFat sd;
SdFile myFile;

void setup() {
  Serial.begin(9600);
  while (!Serial) {}  // wait for Leonardo
  Serial.println("Type any character to start");
  while (Serial.read() <= 0) {}
  delay(400);  // catch Due reset problem
  
  // Initialize SdFat or print a detailed error message and halt
  // Use half speed like the native library.
  // change to SPI_FULL_SPEED for more performance.
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

  // open the file for write at end like the Native SD library
  if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
    sd.errorHalt("opening test.txt for write failed");
  }
  // if the file opened okay, write to it:
  Serial.print("Writing to test.txt...");
  myFile.println("testing 1, 2, 3.");

  // close the file:
  myFile.close();
  Serial.println("done.");

  // re-open the file for reading:
  if (!myFile.open("test.txt", O_READ)) {
    sd.errorHalt("opening test.txt for read failed");
  }
  Serial.println("test.txt:");

 // read from the file until there's nothing else in it:
  int data;
  while ((data = myFile.read()) >= 0) {
    Serial.write(data);
  }
  // remove the file:
  if (!myFile.remove()) Serial.println("Error file.remove");
}


void loop() {
  // nothing happens after setup
}

What happens is that everything goes well, except for removing the file.
Continuous runs just append the data.

Here's the output:

Type any character to start
Writing to test.txt...done.
test.txt:
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.
Error file.remove

Any ideas? Apparently the connection to SD card is fine, since it can read and write.
Edit:
tried to get the newest version of the library, but cannot see any difference. Still doesn't work. Took a look at the cpp code, but can't really determine where it goes wrong... truncating or something else...
Any ideas how to debug this?

Edit 2:
Solved it, by replacing

myFile.remove();

with

sd.remove("test.txt")

Still would like to know how this can be caused, feels like a workaround and I can't imagine this should be regarded a bug in the library. I also realize this solution is also mentioned in this thread, didn't think it applied on my case :zipper_mouth_face: