n. Check File/Dir. Existence - FStat()

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 17 - CleO File System >

n. Check File/Dir. Existence - FStat()

The FStat() command is used to check the existence of a file/directory.



Command Prototype


int cmd_FStat( const char* Path, const char* FileInfoBuf);






The location of the directory


Buffer to store file/directory information. To check the existence, this should be set to NULL. To get the file/directory info, provide a pointer of structure file_info_t to the command.





void setup() {

 int file;

 char buf[9];

 int bytewritten;

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



/* Start building a screen frame */



 CleO.StringExt(FONT_MEDIUM, 400, 100, LIGHT_GREEN, TM, 0, 0,

 "Create TestFStat.txt...");

 file = CleO.FOpen("@TestFStat.txt", FILE_CREATE_ALWAYS | FILE_WRITE);


 //Confirm if the file exist

  if(CleO.FStat("@TestFStat.txt", NULL) == 1) {

    CleO.StringExt(FONT_MEDIUM, 400, 150, LIGHT_GREEN, TM, 0, 0,

    "TestFStat.txt OK");    

  } else {

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

    "TestFStat.txt FAILED");     





void loop() {}





The above code snippet opens the test.txt file in write mode. The code highlighted in yellow color shows how the FStat() command checks for the existence of a file or directory and displays an appropriate message accordingly. The @ symbol is used only when performing the file operation from the eFlash and not from the SD Card.





Here is the output displayed upon executing the code snippet -