uce/site/doc/pages/file_exists.txt
2026-06-16 23:02:45 +00:00

20 lines
636 B
Plaintext

:sig
bool file_exists(String path)
:params
path : path to check, resolved against the unit's directory
return value : true if a regular file exists at `path`
:content
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");
:see
>sys
file_stat
file_unlink