file ... exists

operator

Return type:
Switch
Returns:
true if the system path named by string-expression exists, and false otherwise.
Syntax
file string-expression exists


Purpose

The file ... exists test is used to determine if the system path named by string-expression exists. This is useful to avoid a program error when reading a file, or to avoid overwriting an existing file.

Example

The following program shows how file ... exists test is used to avoid overwriting the file errors.log:

  process
     local stream errors
  
     do when file "errors.log" exists
        put #log "File errors.log already exists. Please delete or rename it before running this program.%n"
        halt with 1
     done
  
     open errors as file "errors.log"