本地文件

remove()

files.remove(target) → Promise<{ ok: true }>

删除文件、 文件夹和它下的所有内容。 没有什么被保存, 工作空间根不能成为目标 。

freerecursive on a folderno recycle bin
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

参数

targetstring必填

要删除的文件或文件夹。 工作空间根被拒绝 。

await pc.files.remove("Launch plan/draft.md");
// { ok: true }

// A folder goes with its contents, at every depth
await pc.files.remove("Archive/2026");
pc.files.remove("Launch plan/draft.md")
# {"ok": True}

# A folder goes with its contents, at every depth
pc.files.remove("Archive/2026")
文件夹已删除, 文件夹中的所有内容都已删除

文件夹不是空的, 也没有列出去向, 不存在拒绝。 如果您想知道, 请先列出它; 如果您想要它返回, 请将其移到一边 。

工作空间本身被拒绝

remove("") 加加加 invalid_path。 清空工作空间不是这种类提供的操作—— 它掌握着机器上每个应用程序的文件, 而不仅仅是你的。

可回收版本

最好在路径来自模型、形式或任何您没有计算自己的东西时移动到隐藏文件夹, 费用相同, 并且可以逆转 。

const stamp = new Date().toISOString().replace(/[:.]/g, "-");

// Reversible
await pc.files.move(path, `.trash/${stamp}/${path}`);

// Final
await pc.files.remove(path);
# Reversible: trash() moves it under .trash/<stamp>/
pc.files.trash(path)

# Final
pc.files.remove(path)

错误

代码状态触发条件
path_not_found404这条路没有路,第二次卸下两次就涨了
invalid_path400绝对,在工作空间之外,或者根
local_files_require_node400运行环境没有文件系统。
storage_not_on_this_machine409另一台电脑的储藏室
import { IaGenifyError } from "iagenify";

async function removeIfThere(files, path) {
  try {
    await files.remove(path);
    return true;
  } catch (err) {
    if (err instanceof IaGenifyError && err.code === "path_not_found") return false;
    throw err;
  }
}
def remove_if_there(files, path):
    if not (files.root / path).exists():
        return False
    files.remove(path)
    return True