Prototype: fileexists(filename)

Return type: boolean

Description: Returns whether the file filename can be accessed.

The file must exist, and the user must have access permissions to the file for this function to return true.

Notes:

  • fileexists() does not resolve symlinks. If a broken symlink exists, the file is seen to exist. For this functionality use filestat("myfile", "link target") to see if a file resolves to a the expected target, and check if the link target exists. Alternatively use test with returnszero(), for example returnszero("/bin/test -f myfile").

Arguments:

  • filename: string - File object name - in the range: "?(/.*)

Example:

code
body common control
{
      bundlesequence  => { "example" };
}

bundle agent example
{
  classes:
      # this.promise_filename has the currently-executed file, so it
      # better exist!
      "exists" expression => fileexists($(this.promise_filename));
      "exists_etc_passwd" expression => fileexists("/etc/passwd");

  reports:

    exists::

      "I exist!  I mean, file exists!";
}

Output:

code
R: I exist!  I mean, file exists!

See also: filestat(), isdir(), islink(), isplain(), returnszero()