Files
marqdo/lib/fs.mq.md
T
cflmyandCursor 94ae6713aa feat(stdlib): Mid M2 path algebra and fs copy/move/temp
Add lib/path (EN/ZH) and thicken fs with sandboxed copy_file, move,
and make_temp, with golds and public demos.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-07 20:10:12 +08:00

85 lines
1.6 KiB
Markdown

---
title: lib/fs
description: English filesystem wrappers
---
## read_text
+ `path`
**> host_read_text path=`path`**
## write_text
+ `path`
+ `text`
**> host_write_text path=`path` text=`text`**
## append_text
+ `path`
+ `text`
**> host_append_text path=`path` text=`text`**
## exists
+ `path`
**> host_exists path=`path`**
## list_dir
+ `path`
**> host_list_dir path=`path`**
## make_dir
+ `path`
**> host_make_dir path=`path`**
## remove
+ `path`
**> host_remove path=`path`**
## copy_file
+ `src`
+ `dest`
Copy a file (overwrites `dest` if it exists). Paths are sandboxed like other fs ops.
**> host_copy_file src=`src` dest=`dest`**
## move
+ `src`
+ `dest`
Rename / move within the sandbox.
**> host_move src=`src` dest=`dest`**
## make_temp
+ `prefix`=None
Create an empty temp file under the program directory; return its relative path.
**> host_make_temp prefix=`prefix`**
## text_patch
+ `path`
+ `find`
+ `replace`
Exact FIND→REPLACE once in a UTF-8 text file. `find` must match exactly once.
**> host_text_patch path=`path` find=`find` replace=`replace`**
## apply_patch_blocks
+ `path`
+ `text`
+ `soft`=False
Apply plan-style triple-angle FIND/REPLACE blocks from `text` to `path`.
Also accepts fenced find/replace pairs and minimal Begin Patch hunks.
When `soft=True`, **only** “FIND not found” returns `0` (run continues). Empty FIND, multi-match, parse errors, and whole-file FIND still abort — whole-file rewrite is forbidden.
**> host_apply_patch_blocks path=`path` text=`text` soft=`soft`**