file-exists? - test if a file exists

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs files))               ;R6RS
(import (scheme file))              ;R7RS

SYNOPSIS

(file-exists? filename)

DESCRIPTION

This procedure returns #t if the named file exists at the time the procedure is called and #f otherwise.

RETURN VALUES

Returns a single boolean object.

EXAMPLES

;; Assuming a typical Unix-like system
(file-exists? "/dev/null")
          => #t

APPLICATION USAGE

This procedure is used to check if a file exists before trying to perform some operation on it. One common usage is in a Scheme implementation's library loader, which needs to check if a base filename exists in one of multiple paths, often trying different file extensions.

COMPATIBILITY

R6RS
Valid values for a file name include strings that name a file using the native notation of filesystem paths on an implementation’s underlying operating system, and may include implementation-dependent values as well.
R7RS
It is an error if filename is not a string. See the next section.

This procedure is absent from R5RS and earlier reports.

ERRORS

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
R7RS
The assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

SEE ALSO

delete-file(3scm), open-input-file(3scm), open-output-file(3scm)

STANDARDS

R6RS, R7RS

HISTORY

This procedure is new in R6RS and its description was copied into R7RS. It is absent from previous reports. Early Scheme running on MacLISP could use the procedure allfiles to check if a file exists.

AUTHORS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.

BUGS

Programs that check if a file exist and then immediately operate on it are prone to race conditions. The file may have been removed immediately after this procedure checked for its existence, or it might have been created. This is often not a problem.


Markup created by unroff 1.0sc,    March 04, 2023.