# move()

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

`files.move(from, to) → Promise<Item>`

移动或重命名文件或文件夹。 它拒绝覆盖, 这使得您可以安全地在您没有检查的路径上调用 。

Status: free · never overwrites · files and folders

## 参数 {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `from` | string | 必填 | 移动什么。 文件或文件夹 。 |
| `to` | string | 必填 | 其去向。 它的父文件夹是创建的 。 |

```javascript
// Rename
await pc.files.move("notes.md", "Launch plan/notes.md");

// Move a whole folder
await pc.files.move("Launch plan", "Archive/2026/Launch plan");
// { name: "Launch plan", path: "Archive/2026/Launch plan", type: "folder", … }
```

## 拒绝而不是取代 {#no-overwrite}

已经上升的目的地 `path_exists`。没有移动,没有丢失, 和决定如何 如何处理碰撞 与你。

```javascript
import { IaGenifyError } from "iagenify";

async function moveAside(files, from, to) {
  try {
    return await files.move(from, to);
  } catch (err) {
    if (err instanceof IaGenifyError && err.code === "path_exists") {
      const stamp = new Date().toISOString().slice(0, 10);
      return files.move(from, to.replace(/(\.[^.]+)?$/, ` (${stamp})$1`));
    }
    throw err;
  }
}
```

## 文件夹不能在内部移动 {#into-itself}

`move("Work", "Work/old")` 拒绝拒绝时 `invalid_path`,在任何被触碰之前。将操作在中途或循环失败的文件系统左侧。

## 这就是如何建造回收箱的 {#trash}

> **移动到点点文件夹是您可以撤销的删除**
>
> 隐藏条目不在列表() 中, 所以移动某些在. trash / 下的东西/ 保存每个字节时将其从视图中删除。这正是该代理删除工具的作用,您也可以这样做。

```javascript
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
await pc.files.move("Launch plan/draft.md", `.trash/${stamp}/Launch plan/draft.md`);
```

## 错误 {#errors}

| 代码 | 状态 | 触发条件 |
| --- | --- | --- |
| path_not_found | 404 | 什么都没有 `from`. |
| path_exists | 409 | `to` 被拍摄。 |
| invalid_path | 400 | 绝对的,在工作空间之外,根,或者一个文件夹本身。 |
| local_files_require_node | 400 | 运行环境没有文件系统。 |
| storage_not_on_this_machine | 409 | 另一台电脑的储藏室 |

- [remove()](/zh/sdk/ref/local-files/remove): 真正删除, 当移动偏移不是你想要的时 。
- [本地文件](/zh/sdk/ref/local-files): 工作空间、 路径规则、 以及每个方法返回的形状 。

```python
# Rename
pc.files.move("notes.md", "Launch plan/notes.md")

# Move a whole folder
pc.files.move("Launch plan", "Archive/2026/Launch plan")
# {"path": "Archive/2026/Launch plan"}
```

```python
import re
from datetime import date

def move_aside(files, source, destination):
    if (files.root / destination).exists():
        stamp = date.today().isoformat()
        destination = re.sub(r"(\.[^.]+)?$", lambda m: f" ({stamp}){m.group(1) or ''}", destination, count=1)
    return files.move(source, destination)
```

```python
from datetime import datetime, timezone

stamp = datetime.now(timezone.utc).isoformat().replace(":", "-").replace(".", "-")
pc.files.move("Launch plan/draft.md", f".trash/{stamp}/Launch plan/draft.md")
```
