std.fs Module Reference

The std.fs module provides synchronous and asynchronous file system operations with cross-platform path handling.

fs_example.sp
1import std.io;
2import std.fs;
3
4fn main() -> void {
5 let path = "server.log";
6 fs.writeText(path, "INFO: Starting SP microservice on port 8080\n");
7
8 if (fs.exists(path)) {
9 let content = fs.readText(path);
10 println("Log contents:\n${content}");
11 fs.delete(path);
12 }
13}

Exported Functions

fs.readText

Native Builtin
fn fs.readText(string path) -> string

Reads the entire contents of a file as a UTF-8 string.

Parameters
path(string)
Path to the target file.
Returns:string

fs.writeText

Native Builtin
fn fs.writeText(string path, string content) -> bool

Overwrites or creates a file with the provided text content.

Parameters
path(string)
Target file path.
content(string)
Data to write.
Returns:bool (true if successful)

fs.exists

Native Builtin
fn fs.exists(string path) -> bool

Returns true if a file or directory exists at path.

Parameters
path(string)
File path.
Returns:bool

fs.delete

Native Builtin
fn fs.delete(string path) -> bool

Deletes the file at the given path.

Parameters
path(string)
File to delete.
Returns:bool