FEXISTS

The FEXISTS function returns a boolean value indicating whether a file or directory exists.

The filename can include a full path to the file, but if it is a relative path then see how files are located for more information on how the path is resolved.

When running a project from an XJPack file and the filename is relative, FEXISTS will look inside the XJPack file first: see the discussion on how files are located. However, if FEXISTS is called with the name of a directory inside the XJPack file, it will always return FALSE.

Syntax

FEXISTS( STRING filename )

Parameters

filename
The filename to check for existence.

Return value

A boolean value indicating whether the file or directory specified by filename exists or not.

Example

LOCAL WriteFile()()
  FILE fileHandle;
  CONST STRING name := "test.bin";
  INT ch;

  IF FEXISTS(name) THEN
    PRINT("File ", name, " already exists, do you want to continue?");
    ch := WAITKEY();
    IF ch != 'Y' &&? ch != 'y' THEN
      RETURN;
    END;
  END;

  fileHandle := FOPEN(name, "w");

  // Perform file operations on the file handle...

  FCLOSE(fileHandle);
END;