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;34fn main() -> void {5 let path = "server.log";6 fs.writeText(path, "INFO: Starting SP microservice on port 8080\n");78 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 Builtinfn 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:
stringfs.writeText
Native Builtinfn 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 Builtinfn fs.exists(string path) -> bool
Returns true if a file or directory exists at path.
Parameters
path(string)
File path.Returns:
boolfs.delete
Native Builtinfn fs.delete(string path) -> bool
Deletes the file at the given path.
Parameters
path(string)
File to delete.Returns:
bool