(scheme file)
(scheme file) - R7RS File Library
File input/output operations for opening, reading, and writing files.
See: R7RS Small §6.13.1
For extended filesystem operations (directories, globs, metadata), use (sigil fs) instead.
Exports
call-with-input-fileprocedureCall a procedure with an input port, ensuring cleanup.
Opens the file, passes the port to proc, closes the port, and returns proc's result. The port is closed even if proc raises an error.
(call-with-input-file "data.txt"
(lambda (port)
(read-line port)))Re-exported from (sigil io)
call-with-output-fileprocedureCall a procedure with an output port, ensuring cleanup.
Opens the file, passes the port to proc, closes the port, and returns proc's result.
(call-with-output-file "output.txt"
(lambda (port)
(write-string "Hello!" port)))Re-exported from (sigil io)
open-input-fileprocedureOpen a file for reading text.
Returns an input port. The port should be closed with close-input-port when done, or use call-with-input-file for automatic cleanup.
(let ((port (open-input-file "data.txt")))
(let ((line (read-line port)))
(close-input-port port)
line))Re-exported from (sigil io)
open-output-fileprocedureOpen a file for writing text.
Creates the file if it doesn't exist, truncates if it does. The port should be closed with close-output-port when done.
(let ((port (open-output-file "output.txt")))
(write-string "Hello!" port)
(close-output-port port))Re-exported from (sigil io)