UCE Docs / file_exists

Signature

bool file_exists(String path)

Parameters

path : path to check, resolved against the unit's directory
return value : true if a regular file exists at path

Reports whether a regular file exists. Use it to guard reads or to confirm a write or delete took effect. It is file-oriented and returns false for directories — use file_stat() and check is_dir to test for a directory.

Example

file_put_contents("/tmp/doc-exists.txt", "x");
print(file_exists("/tmp/doc-exists.txt") ? "exists" : "missing", " / ");
print(file_exists("/tmp/doc-not-here-xyz.txt") ? "exists" : "missing", "\n");
Output
exists / missing