Native directory trees, enumeration and file metadataok
文档
怎样读这份可执行文档
正文说明意图,标记指出哪些片段会执行。遮蔽只在正文显示动作说明,实际逻辑放在侧注;阅读、展开与定位都不会运行代码。
| 标记 | 阅读含义 |
|---|---|
无标记文字 | 作者的解释,按普通 Markdown 阅读。 |
空行 | 分隔叙述与结构,不是计算步骤。 |
# / ## | 一级标题声明对象或入口,更深标题声明函数;说明按钮可查看输入、返回与依据。 |
> | 调用函数;实际执行结果另有标注。 |
1. 递增 | 按条件选择分支,不是普通编号说明。 |
- | 重复或遍历结构;迭代选择器只切换已有运行记录。 |
+ `名` | 兼容的显式形参;新库优先在叙述中声明参数,标题下的表格解释契约。 |
GFM 表 | 未绑定的契约表是说明;绑定表按列、行和 @ 形态构成数据。 |
```lang | 代码块;绑定的外语代码与普通示例区分展示,数学公式另有公式卡片。 |
--- / *** | 分隔内容,不能把分隔线当作函数返回。 |
<!-- marqdo-out --> | 程序写回的结果,区别于作者原始正文。 |
`名` | 叙述中的参数或变量;默认值跟在名称之后。 |
**…** | 执行语句:赋值、调用或计算;不是打印,也不是返回。 |
*…* | 返回表达式;句中以返回、Return 等明确引出。 |
*None* / **** | 显式返回空值或结束当前函数。 |
[键](集合) | 正文显示描述,侧注按函数与参数、可跳转链接、结构化内容展示括号内的细节;空括号表示待补充实际逻辑。阅读不会执行调用。classic 模式保留旧链接取元。 |
修饰… [函数] … | 兼容的带修饰调用;不能把任意普通链接当作执行授权。 |
集合[^键] | 兼容的脚注取元;当前库优先用 access 读取集合。 |
*仅* / **说明** | 普通强调仍属于文字;界面按真实解析结果区分强调、语句与返回。 |
This complete demonstration uses native filesystem tools. Call main with fs.write and a disposable --fs-root. It returns actual metadata and relative paths after cleaning its own temporary directory.
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Actual byte size, directory entry count and relative paths |
Create a unique temporary directory, then one child directory and one text file. Every write remains under the granted root, avoiding collisions with a pre-existing demo folder. Paths are built explicitly; no generated reader/writer or foreign process participates.
The content ok occupies two UTF-8 bytes. File size measures stored bytes rather than text character count. Enumeration returns relative paths for the child directory and file; counting those paths is another distinct observation. The example does not depend on operating-system enumeration order. Sort explicitly if a later workflow requires stable ordering.
Collect the real metadata and paths before removing this run's unique tree. Returned paths describe an observation, not still-live artifacts. A failure can retain its native diagnostic and this run's directory for caller inspection. Cleanup must stay scoped to the directory created by this invocation.
函数调用Create a unique directory inside the granted root
fs.temp_dir- prefix
- fs-tree-demo
原始写法
fs.temp_dir(prefix="fs-tree-demo")函数调用Create this run own child directory
fs.make_dirs- path
`child`
原始写法
fs.make_dirs(path=`child`)函数调用Write the exact UTF-8 example content
fs.write_text- path
`note`- text
- ok
原始写法
fs.write_text(path=`note`, text="ok")函数调用Read the actual file metadata
fs.stat- path
`note`
原始写法
fs.stat(path=`note`)函数调用Enumerate this run directory entries
fs.walk- path
`work`
原始写法
fs.walk(path=`work`)函数调用Retain storage byte size
access- 参数 1
`metadata`- 参数 2
- size
原始写法
access(metadata, "size")函数调用Count the actual enumerated paths
len- 参数 1
`paths`
原始写法
len(`paths`)函数调用Remove only this run unique directory tree
fs.remove_tree- path
`work`
原始写法
fs.remove_tree(path=`work`)| size | entries | paths |
|---|---|---|
size | entries | paths |
Functions
Variables
-
child textfs-tree-demo-643943bb26f08721ad890499a36db233/subfs-tree-demo-643943bb26f08721ad890499a36db233/sub
-
entries int22
-
markup textocclusionocclusion
-
metadata map · 4
size 2 mtime_unix 1794999072 is_file True is_dir False key value size 2 mtime_unix 1794999072 is_file True is_dir False -
note textfs-tree-demo-643943bb26f08721ad890499a36db233/readme.txtfs-tree-demo-643943bb26f08721ad890499a36db233/readme.txt
-
observed map · 3
size 2 entries 2 paths List(2) key value size 2 entries 2 paths # value 1 readme.txt 2 sub -
paths list · 2
# value 1 readme.txt 2 sub # value 1 readme.txt 2 sub -
size int22
-
title textNative directory trees, enumeration and file metadataNative directory trees, enumeration and file metadata
-
work textfs-tree-demo-643943bb26f08721ad890499a36db233fs-tree-demo-643943bb26f08721ad890499a36db233
可执行知识 · 输入、返回与依据
这份文档怎样成为可调用的知识
1 个知识单元 · 16 个结构步骤。先读输入、返回与调用边界,再按需查看依赖和依据。
以下来自静态分析,不代表程序已经运行、测试通过或内容已获领域确认。实际运行见正文标注与“运行与结果”。
main函数
需要什么输入
无需提供输入参数。
返回什么
map · Actual byte size, directory entry count and relative paths
调用边界
读取文件、写入文件。权限由实际运行入口授予;静态副作用信息不等于运行许可。
当前有哪些依据
- 语法与引用
- 检查通过;检查通过
- 契约检查
- 尚未检查
- 测试记录
- 没有可用记录
- 内容来源
- 尚无已核验证据
- 领域审阅
- 尚未进行领域审阅
查看本单元的结构步骤
这是源码结构,不是实际执行时序;正文引用不会因阅读而执行。
- 调用Create a unique directory inside the granted root
- 正文引用Create this run own child directory
- 正文引用Write the exact UTF-8 example content
- 正文引用Read the actual file metadata
- 正文引用Enumerate this run directory entries
- 正文引用Retain storage byte size
- 正文引用Count the actual enumerated paths
- 正文引用Remove only this run unique directory tree
- 调用Create this run own child directory
- 调用Write the exact UTF-8 example content
- 调用Read the actual file metadata
- 调用Enumerate this run directory entries
- 观察Retain storage byte size
- 调用Count the actual enumerated paths
- 调用Remove only this run unique directory tree
- 正文引用Create a unique directory inside the granted root
技术详情:身份、摘要与原始状态
- 目标标识
mq://public/features%2F16-fs-mid2/function/main- 制品摘要(未检查锁定状态)
sha256:cbd887d8793dbc9097969f71f88b18d2f489e34b8b8bd6b766ef4b3764eb4b15- 依赖标识
- 原始验证状态
parse: passed; resolve: passed; contract: unchecked; execution: not_run; tests: unknown; evidence: unverified; domain: unreviewed
运行与结果
完整源码
--- markup: occlusion title: Native directory trees, enumeration and file metadata import: fs: lib/fs.mq.md --- This complete demonstration uses native filesystem tools. Call main with fs.write and a disposable --fs-root. It returns actual metadata and relative paths after cleaning its own temporary directory. ## main | 返回 | 类型 | 说明 | |---|---|---| | result | map | Actual byte size, directory entry count and relative paths | Create a unique temporary directory, then one child directory and one text file. Every write remains under the granted root, avoiding collisions with a pre-existing demo folder. Paths are built explicitly; no generated reader/writer or foreign process participates. The content ok occupies two UTF-8 bytes. File size measures stored bytes rather than text character count. Enumeration returns relative paths for the child directory and file; counting those paths is another distinct observation. The example does not depend on operating-system enumeration order. Sort explicitly if a later workflow requires stable ordering. Collect the real metadata and paths before removing this run's unique tree. Returned paths describe an observation, not still-live artifacts. A failure can retain its native diagnostic and this run's directory for caller inspection. Cleanup must stay scoped to the directory created by this invocation. We **work = [Create a unique directory inside the granted root](fs.temp_dir(prefix="fs-tree-demo"))** and **child = work + "/sub"** and **note = work + "/readme.txt"**. We **[Create this run own child directory](fs.make_dirs(path=`child`))** and **[Write the exact UTF-8 example content](fs.write_text(path=`note`, text="ok"))**. We **metadata = [Read the actual file metadata](fs.stat(path=`note`))** and **paths = [Enumerate this run directory entries](fs.walk(path=`work`))** and **size = [Retain storage byte size](access(metadata, "size"))** and **entries = [Count the actual enumerated paths](len(`paths`))**. We **[Remove only this run unique directory tree](fs.remove_tree(path=`work`))** after collecting the observations. `observed` = | size | entries | paths | |---|---|---| | `size` | `entries` | `paths` | After observing and cleaning this run we return *observed*.