file-exists?(3scm)
πΈ NAME πΈ
file-exists? β test if a file exists. Okay bestie, this is the file-exists?(3scm) page from the Scheme Programmer's Manual, and it's literally your little βdoes this file exist?β check. Iconic. π
π LIBRARY π
Import it from whichever report you're living in, no cap:
(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. That timing detail is lowkey important, bestie. β°
π RETURN VALUES π
Returns a single boolean object. One boolean, no extras. Simple, clean, slay. β
π 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. Look-before-you-leap energy fr fr. π
π§ 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. Not in the old reports, ngl. π
π 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. Yes, βfail catastrophicallyβ is right there β dramatic but accurate. π
π₯ 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. History lesson, but make it cute. π«Ά
π 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/. Credit where credit is due, bestie. π
π 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.
Like, usually fine, but don't say nobody warned you. π
Catch you later, bestie β this file-exists?(3scm) page is from the Scheme Programmer's Manual and it's dated 2021-03-07. Mwah! πβ¨
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2021 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms