# remove()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/local-files/remove/
Language: zh

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

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

Status: free · recursive on a folder · no recycle bin

## 参数 {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `target` | string | 必填 | 要删除的文件或文件夹。 工作空间根被拒绝 。 |

```javascript
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");
```

> **文件夹已删除, 文件夹中的所有内容都已删除**
>
> 文件夹不是空的, 也没有列出去向, 不存在拒绝。 如果您想知道, 请先列出它; 如果您想要它返回, 请将其移到一边 。

## 工作空间本身被拒绝 {#root}

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

## 可回收版本 {#recoverable}

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

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

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

// Final
await pc.files.remove(path);
```

## 错误 {#errors}

| 代码 | 状态 | 触发条件 |
| --- | --- | --- |
| path_not_found | 404 | 这条路没有路,第二次卸下两次就涨了 |
| invalid_path | 400 | 绝对,在工作空间之外,或者根 |
| local_files_require_node | 400 | 运行环境没有文件系统。 |
| storage_not_on_this_machine | 409 | 另一台电脑的储藏室 |

```javascript
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;
  }
}
```

- [move()](/zh/sdk/ref/local-files/move): 改变东西的方法
- [本地文件](/zh/sdk/ref/local-files): 工作空间、 路径规则、 以及每个方法返回的形状 。

```python
pc.files.remove("Launch plan/draft.md")
# {"ok": True}

# A folder goes with its contents, at every depth
pc.files.remove("Archive/2026")
```

```python
# Reversible: trash() moves it under .trash/<stamp>/
pc.files.trash(path)

# Final
pc.files.remove(path)
```

```python
def remove_if_there(files, path):
    if not (files.root / path).exists():
        return False
    files.remove(path)
    return True
```
