b. Close File - FClose()

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 17 - CleO File System >

b. Close File - FClose()

The FClose() command is used to close an open file.

 

 

Command Prototype

 

uint16_t FClose(int16_t Handle);

 

Parameters

Description

Handle

Returns value from FOpen()

 

 

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, 100, 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, 240, 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, 380, LIGHT_GREEN, TM, 0, 0, buf);

 

/* Close file using file handle */

CleO.FClose(f);

 

/* Display completed screen frame */

 CleO.Show();

}

 

void loop() { }

 

 

Description

 

In the above code snippet, the code highlighted in yellow color shows how the file close operation is performed using the FClose() command. The cached information of the file is written back to the volume if any data is written to the file. Upon executing the command, the file object is no longer valid, and it can be discarded. Use the @ symbol only when performing the file operation from the eFlash and not from the SD Card.