fs
Types
EditResult
type EditResult = {
replacements: number;
path: string
}(source)
Edit
type Edit = {
oldText: string;
newText: string;
replaceAll: boolean
}(source)
MultiEditResult
type MultiEditResult = {
replacements: number;
path: string;
edits: number
}(source)
PatchResult
type PatchResult = {
applied: number;
files: string[]
}(source)
Functions
edit
edit(filename: string, oldText: string, newText: string, replaceAll: boolean, dir: string): ResultEdit a file by replacing oldText with newText. By default oldText must match exactly once in the file; pass replaceAll=true to replace every occurrence. Fails if oldText is not found or appears multiple times (unless replaceAll is set).
@param filename - The file to edit @param oldText - The text to find @param newText - The replacement text @param replaceAll - Replace all occurrences instead of just the first @param dir - The directory to resolve the filename against (defaults to ".")
Parameters:
| Name | Type | Default |
|---|---|---|
| filename | string | |
| oldText | string | |
| newText | string | |
| replaceAll | boolean | false |
| dir | string | "." |
Returns: Result
Throws: std::edit
(source)
multiedit
multiedit(filename: string, edits: Edit[], dir: string): ResultApply a sequence of edits to a single file atomically. Each edit has oldText, newText, and replaceAll. Fails if any edit's oldText is not found or is ambiguous; when any edit fails, nothing is written.
@param filename - The file to edit @param edits - Array of edit objects with oldText, newText, and replaceAll @param dir - The directory to resolve the filename against (defaults to ".")
Parameters:
| Name | Type | Default |
|---|---|---|
| filename | string | |
| edits | Edit[] | |
| dir | string | "." |
Returns: Result
Throws: std::multiedit
(source)
applyPatch
applyPatch(patch: string): ResultApply a unified diff to the working tree. Supports file creation (--- /dev/null), line additions, deletions, and context. Fails on a malformed diff or on a context-line mismatch against the current file contents.
Parameters:
| Name | Type | Default |
|---|---|---|
| patch | string |
Returns: Result
Throws: std::applyPatch
(source)
mkdir
mkdir(dir: string): ResultCreate a directory, including any missing parent directories. Idempotent: succeeds if the directory already exists. Fails if a non-directory entry already occupies the path, or on permission errors.
Parameters:
| Name | Type | Default |
|---|---|---|
| dir | string |
Returns: Result
Throws: std::mkdir
(source)
copy
copy(src: string, dest: string, allowedPaths: string[]): ResultCopy a file or directory. Directories are copied recursively. Fails if src does not exist or dest cannot be written. Set allowedPaths to restrict which path prefixes are permitted.
@param src - The source path @param dest - The destination path @param allowedPaths - Only allow paths starting with these prefixes
Parameters:
| Name | Type | Default |
|---|---|---|
| src | string | |
| dest | string | |
| allowedPaths | string[] | [] |
Returns: Result
Throws: std::copy
(source)
move
move(src: string, dest: string, allowedPaths: string[]): ResultMove or rename a file or directory. Falls back to copy+remove if src and dest are on different filesystems. Fails if src does not exist. Set allowedPaths to restrict which path prefixes are permitted.
@param src - The source path @param dest - The destination path @param allowedPaths - Only allow paths starting with these prefixes
Parameters:
| Name | Type | Default |
|---|---|---|
| src | string | |
| dest | string | |
| allowedPaths | string[] | [] |
Returns: Result
Throws: std::move
(source)
remove
remove(target: string, allowedPaths: string[]): ResultDelete a file or directory. Directories are removed recursively. Does not fail if the target does not exist. Set allowedPaths to restrict which path prefixes are permitted.
@param target - The path to delete @param allowedPaths - Only allow paths starting with these prefixes
Parameters:
| Name | Type | Default |
|---|---|---|
| target | string | |
| allowedPaths | string[] | [] |
Returns: Result
Throws: std::remove
(source)