参数
dirstring要读取的文件夹, 相对于工作空间。 空( 默认) 读取工作空间本身 。
recursivebooleanfalse整棵树走完,然后回来 只保存文件,他们完全的相对路径。
一级
await pc.files.list();
// [
// { name: "Launch plan", path: "Launch plan", type: "folder", size: null, mimeType: null, modifiedAt: "…" },
// { name: "notes.md", path: "notes.md", type: "file", size: 1284, mimeType: "text/markdown", modifiedAt: "…" }
// ]
await pc.files.list("Launch plan");
// [ { name: "brief.md", path: "Launch plan/brief.md", type: "file", … } ]pc.files.list()
# [
# {"name": "Launch plan", "path": "Launch plan", "type": "folder", "size": 0},
# {"name": "notes.md", "path": "notes.md", "type": "file", "size": 1284}
# ]
pc.files.list("Launch plan")
# [{"name": "brief.md", "path": "Launch plan/brief.md", "type": "file", …}]文件夹在文件之前出现, 每个组会按路径排序。 此顺序是稳定的, 这样列表可以随着它到达时显示 。
整棵树
recursive: true 不仅它去的深度:文件夹不再是他们自己的条目。你得到的文件,每个文件都携带着您可以直接通过的路 read().
const files = await pc.files.list("", { recursive: true });
// Every file, no folder entries
const markdown = files.filter((f) => f.mimeType === "text/markdown");
const bytes = files.reduce((total, f) => total + f.size, 0);files = [f for f in pc.files.list("", recursive=True) if f["type"] == "file"]
# Every file, no folder entries
markdown = [f for f in files if f["path"].endswith(".md")]
total_bytes = sum(f["size"] for f in files)上限为500件,没有报告
单步停止 。 单步停止只要它有500个条目。 没有旗帜可以这么说, 而在大型工作空间上很重要 : 要通过更多, 一次列出文件夹而不是根递现 。
并非结果
以点开头的名称在每级别跳过条目的条目。 dir 也让垃圾桶能保持畅通,
错误
| 代码 | 状态 | 触发条件 |
|---|---|---|
| path_not_found | 404 | 此路径没有文件夹 。 |
| not_a_folder | 400 | 路径中命名文件。 |
| invalid_path | 400 | 绝对的,或者在工作空间之外 |
| local_files_require_node | 400 | 运行环境没有文件系统。 |
| storage_not_on_this_machine | 409 | 另一台电脑的储藏室 |
import { IaGenifyError } from "iagenify";
async function listOrEmpty(files, dir) {
try {
return await files.list(dir);
} catch (err) {
if (err instanceof IaGenifyError && err.code === "path_not_found") return [];
throw err;
}
}from iagenify import IaGenifyError
def list_or_empty(files, directory):
try:
return files.list(directory)
except IaGenifyError as error:
if error.code == "path_not_found":
return []
raise