delete-file(3scm) Scheme Programmer's Manual delete-file(3scm)

delete-file - delete a file

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

(delete-file filename)

Deletes the named file if it exists and can be deleted.

R6RS
Returns unspecified values.
R7RS
Returns an unspecified value.

(call-with-output-file "temp.txt"
  (lambda (p)
    (display "Hello, temporary world!\n" p)))
(delete-file "temp.txt")

This procedure is used to delete files. It is commonly used to remove existing output files before writing new output files. In R6RS systems this is handled without race conditions with (file-options no-fail), see file-options(3scm).

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.

This procedure can raise exceptions that satisfy the following predicates.
assertion-violation? (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.
i/o-filename-error? (R6RS), file-error? (R7RS)
The file does not exist or cannot be deleted.

file-exists?(3scm), file-options(3scm)

R6RS, R7RS

This procedure is new to R6RS and R7RS, but it existed previously in early Scheme running on MacLISP as deletef.

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

If a program checks if a file exists using file-exists?(3scm) before calling delete-file then another program may still have deleted the file before the second call. It is better to wrap delete-file in guard(3scm). Another approach is to use (file-options no-fail), see file-options(3scm).
2021-03-07