Skip to content

fs

luau
local fs = require("@std/fs")

fs.close

Closes file, flushing any pending writes.

luau
(file: File) -> ()

fs.copy

Copies the file at src to dest.

luau
(src: Pathlike, dest: Pathlike) -> ()

fs.createDirectory

Creates a directory at path. If options.makeParents is true, creates any missing parent directories as well.

luau
(path: Pathlike, options: CreateDirectoryOptions?) -> ()

fs.exists

Returns true if a file or directory exists at path.

luau
(path: Pathlike) -> boolean

Creates a hard link at dest pointing to src.

luau
(src: Pathlike, dest: Pathlike) -> ()

fs.listDirectory

Returns an array of DirectoryEntry values for the immediate children of the directory at path.

luau
(path: Pathlike) -> { DirectoryEntry }

fs.metadata

Returns metadata for the file or directory at path.

luau
(path: Pathlike) -> FileMetadata

fs.open

Opens the file at path in the given mode (defaults to "r"). Returns a file handle.

luau
(path: Pathlike, mode: HandleMode?) -> File

fs.read

Reads the full contents of file and returns them as a string.

luau
(file: File) -> string

fs.readFileToString

Returns the entire contents of the file at filepath as a string.

luau
(filepath: Pathlike) -> string

fs.remove

Removes the file at path.

luau
(path: Pathlike) -> ()

fs.removeDirectory

Removes the directory at path. If options.recursive is true, removes all contents first.

luau
(path: Pathlike, options: RemoveDirectoryOptions?) -> ()

Creates a symbolic link at dest pointing to src.

luau
(src: Pathlike, dest: Pathlike) -> ()

fs.type

Returns the FileType of the entry at path (e.g. "file", "dir", "symlink").

luau
(path: Pathlike) -> FileType

fs.walk

Returns an iterator over all paths under path. If options.recursive is true, descends into subdirectories.

See example/walk_directory.luau for usage.

luau
(path: Pathlike, options: WalkOptions?) -> () -> Path?

fs.watch

Watches path for filesystem changes. Returns a Watcher with a next method that returns the next

WatchEvent, or nil if none is available, and a close method to stop watching.

Note: a while loop must be used rather than a for loop. See example/watch_directory.luau for usage.

luau
(path: Pathlike) -> Watcher

fs.write

Writes contents to file.

luau
(file: File, contents: string) -> ()

fs.writeStringToFile

Writes contents to the file at filepath, replacing any existing contents.

luau
(filepath: Pathlike, contents: string) -> ()