Skip to main content
Version: Stable (v0.95.5)

Fs Module

Hosted interpreter permissions: Filesystem reads, writes, inspection, and enumeration require IO. Fs.combinePath, Fs.parentDirectory, Fs.extension, and Fs.fileNameWithoutExtension require none. These checks do not apply to CLI execution or compilation. See Host permissions.

Paths used for I/O resolve against the host's RootDirectory, not the script's import alias or the current imported file. The CLI defaults to the entry script's directory; environment configuration and --root can override it.

Read and inspect​

FunctionSignatureBehaviorHost permissions
Fs.readTextstring -> string optionReads the whole file; missing or unsafe paths return None.IO
Fs.existsstring -> boolTests whether a file or directory exists; denied or unsafe paths return false.IO
Fs.kindstring -> FsKindReturns File path, Directory path, or Missing. Returned paths are root-relative with / separators.IO
let text = Fs.readText "settings.txt" |> Option.defaultValue ""
match Fs.kind "settings.txt" with
| File path -> Console.writeLine $"file: {path}"
| Directory path -> Console.writeLine $"directory: {path}"
| Missing -> Console.writeLine "missing"

Create and write​

FunctionSignatureArgument order and behaviorHost permissions
Fs.createDirectorystring -> boolCreates the directory and its missing parents. Existing directories succeed.IO
Fs.writeTextstring -> string -> boolpath -> content; writes/replaces the file and creates missing parent directories.IO

These functions return false for unsafe paths or ordinary create/write failures. Denied paths raise an evaluation error.

let saved = Fs.writeText "output/report.txt" "report ready"
Console.writeLine $"saved={saved}"

Work with path strings​

These helpers manipulate strings without reading the filesystem or checking the sandbox. Path interpretation follows the host platform.

FunctionSignatureBehaviorHost permissions
Fs.combinePathstring -> string -> stringleft -> right; combines segments and normalizes separators to /.None
Fs.parentDirectorystring -> string optionReturns the parent portion, or None if absent.None
Fs.extensionstring -> string optionReturns the extension including ., or None if absent.None
Fs.fileNameWithoutExtensionstring -> stringReturns the final filename without its extension.None
let path = Fs.combinePath "src" "main.fss"
let extension = Fs.extension path // Some ".fss"
let name = Fs.fileNameWithoutExtension path // "main"

Discover files​

FunctionSignatureBehaviorHost permissions
Fs.globstring -> string list optionSearches under the root and matches root-relative paths.IO
Fs.enumerateFilesstring -> string -> string list optiondirectory -> pattern; matches paths relative to that directory and returns root-relative paths.IO
let scripts = Fs.glob "**/*.fss" |> Option.defaultValue []
let directFiles = Fs.enumerateFiles "src" "*.fss" |> Option.defaultValue []
let nestedFiles = Fs.enumerateFiles "src" "**/*.fss" |> Option.defaultValue []

* matches within one path segment; ** crosses directories; **/ also permits zero directories; ? matches one character. Separators normalize to /. A separator-free enumerateFiles pattern searches only the selected directory. A pattern containing / allows recursive traversal.

A valid search with no matches returns Some []. Invalid, unavailable, or unsafe search roots return None. Denied files are hidden, denied or symlink/reparse-point directories are skipped, and ordering is not guaranteed. Some inaccessible directories may be skipped rather than fail the whole search.

Filesystem boundaries​

Root checks reject paths that escape the root and symlink/reparse-point paths. Hosts can also set root-relative DeniedPathGlobs. Denied reads raise an error; exists and kind hide denied entries. readText can propagate I/O errors for an existing unreadable file; its option return is not a general exception handler.

These rules apply to the Fs module. Custom .NET providers are executable host code and must enforce their own access policy. See Sandbox and Safety.