Hi,
I have a uSD card which has been formatted to FAT16, I have made a file on this card called "file.txt". I can successfully open and read the contents of the file. However when I want to remove the file and I use the SD.exists("file.txt") it doesn't seem to be able to find the file at all!
Any ideas?
Code as follows:
#include <SPI.h>
#include <SD.h>
File myFile;
void setup()
{
Serial.begin(9600);
//ReadFileContents();
RemoveFile();
}
void RemoveFile()
{
if(SD.exists("file.txt"))
{
SD.remove("file.txt");
Serial.println("file removed");
}
else
{
Serial.println("no file to remove");
}
}
void ReadFileContents()
{
// re-open the file for reading:
myFile = SD.open("file.txt");
if (myFile) {
Serial.println("file.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 file.txt");
}
}