文件系统(1) 本文介绍通过 SDK 使用 AIuse 云电脑 FileSystem 能力的方式。FileSystem 能力用于在云电脑环境中创建目录、读取文件、写入文件、移动文件和搜索文件。 接口清单 接口 说明 createdirectory 创建目录 readfile 读取文本文件内容,支持按偏移量和长度读取 writefile 写入文本文件内容,支持覆盖、追加和新建 movefile 移动或重命名文件、目录 searchfiles 搜索文件 创建目录 plaintext await session.filesystem.createdirectory({ path: 'C:/aiusertest' }); 成功时,业务数据通常包含: plaintext { "path": "C:aiusertest", "created": true } 读取文件 读取文本文件时,可返回文本内容: plaintext const result await session.filesystem.readfile({ path: 'C:/aiusertest/demo.txt', offset: 0, length: 1024 }); console.log(result.data.content); 返回结构示例: plaintext { "path": "C:aiusertestdemo.txt", "offset": 0, "bytesRead": 1024, "encoding": "utf8", "content": "当前片段内容" } 参数说明: 参数 是否必填 说明 path 是 文件路径 offset 否 起始字节偏移,默认 0 length 否 最多读取字节数,默认 0 表示读取剩余内容 当前读取能力面向文本文件。服务端会尝试使用 utf8、utf8sig、gbk 解码。无法解码为文本的文件会返回错误。 写入文件 plaintext await session.filesystem.writefile({ path: 'C:/aiusertest/result.txt', mode: 'overwrite', content: 'task result' }); mode 支持: mode 说明 overwrite 覆盖写入,默认值 append 追加写入 createnew 仅在文件不存在时新建写入 成功时,业务数据通常包含: plaintext { "path": "C:aiusertestresult.txt", "mode": "overwrite", "charsWritten": 11 }
来自: