Description

remove() removes a file from the directory of the serial flash. The actual space used by the file is not reclaimed. However, a new file with this name may be created after the original is removed. Consider recreate() to remove and create the file with the same name again, which is trys to reuse the flash space.

Syntax

remove( filename );

Parameters

char* filename – pointer a zero-terminated char array holding the file name

Returns

bool:
– true if the file could be removed from the directory
– false if not

Example Code

#include "SerialFlash.h"
void setup()
{
  while(!Serial);
  SerialFlash.begin();
  if( SerialFlash.remove("myFile.txt") )
    Serial.println("File could be removed from dir");
  else
    Serial.println("file could NOT be removed");
}
void loop () 
{ }

Notes and Warnings

As mentioned, no space is freed by removing a file from the directory, so if a new file will be created afterwards then additional space will be claimed. Be careful not to unintentionally run out of space by repeated usage of remove() / create() calls. See the file.erase() function as a way to delete only the content of a file so that new data can be written. This might be a better option than remove(), but only in cases when the new content is of less or equal size as the reserved size of the original file. A further option to re-create a file is the function recreate().

See also

GitHub – PaulStoffregen/SerialFlash – org. code this library is based on
c_str() – function to create a 0-terminated char array from a String
erase() – delete content of a file only
recreate() – attempts to use the same flash memory again for a re-created file