if-file-exists ( ..a path true: ( ..a path -- ..b ) false: ( ..a path -- ..b ) -- ..b )


Vocabulary
io.files

Inputs
patha pathname string
truea quotation with stack effect ( ..a path -- ..b )
falsea quotation with stack effect ( ..a path -- ..b )


Outputs
None

Word description
If path is a file that exists, calls the true quotation, otherwise calls the false quotation.

Notes
It is possible for the file to be created or deleted after the call to file-exists? but before running true or false. If that is a concern, you might want to open the file for reading or writing, as needed.

See also
when-file-exists, unless-file-exists

Definition


: if-file-exists
( ..a path true: ( ..a path -- ..b ) false: ( ..a path -- ..b ) -- ..b )
[ dup file-exists? ] 2dip if ; inline