m. Delete File/Directory - FUnLink()

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 17 - CleO File System >

m. Delete File/Directory - FUnLink()

The FUnLink() command is used for deleting a file or directory.

 

 

Command Prototype

 

int cmd_FUnLink( const char* String);

 

 

Parameters

Description

String

The name of the file/directory to be deleted

 

Code

 

 

void setup() {

 char STR1[] = "ABCDEFG";

 int16_t actual;

 

/* Initialize CleO - needs to be done only once */

 CleO.begin();

 

/* Start building a screen frame */

 CleO.Start();

 

 CleO.StringExt(FONT_MEDIUM, 160, 50, LIGHT_GREEN, TM, 0, 0,

 "Creating test.txt...");

/* open file for write */

 int16_t f = CleO.FOpen("@test.txt", FILE_CREATE_ALWAYS | FILE_WRITE);

 

 CleO.StringExt(FONT_MEDIUM, 160, 80, LIGHT_GREEN, TM, 0, 0,

 "Writing ABCDEFG...");

/* write into file */

 CleO.FWrite(f, strlen(STR1) + 1, (uint8_t*)STR1, actual);

 

/* print number of bytes written */

 char buf[30];

 sprintf(buf, "%d bytes written", actual);

 CleO.StringExt(FONT_MEDIUM, 160, 110, LIGHT_GREEN, TM, 0, 0, buf);

 

/* close file using file handle */

 CleO.FClose(f);

CleO.StringExt(FONT_MEDIUM, 160, 140, LIGHT_GREEN, TM, 0, 0,

  "Delete file...");

  CleO.FUnLink("@test.txt");

  //confirm that the file does not exist anymore

  if(CleO.FStat("@test.txt", NULL) == 0)

  {

    CleO.StringExt(FONT_MEDIUM, 160, 170, LIGHT_GREEN, TM, 0, 0,

    "Delete operation successful");  

 }

 else

 {

   CleO.StringExt(FONT_MEDIUM, 160, 200, LIGHT_GREEN, TM, 0, 0,

   "Delete operation failed");  

 }

/* Display completed screen frame */

 CleO.Show();

}

 

void loop() {}

 

 

Description

 

The above code snippet opens the test.txt file in write mode. The code highlighted in yellow color shows how the FUnLink() command deletes the file or directory and displays an appropriate message whether the deletion was successful or not. The @ symbol is used only when performing the file operation from the eFlash and not from the SD Card.

 

 

Output

 

Here is the output displayed upon executing the code snippet -

 

FUnLink