---
title: "Rename box/dir"
method: POST
path: "/boxes/{boxId}/fs/rename"
tags: ["File System"]
---

# Rename box/dir

`POST /boxes/{boxId}/fs/rename`

Renames a file or a directory. If the target newPath already exists, the rename will fail.

## Path parameters

- `boxId` string, required

## Request body

- RenameFile — Request parameters for renaming a file/directory
  - `workingDir` string — Working directory. If not provided, the file will be read from the `box.config.workingDir` directory.
  - `oldPath` string, required — Old path in the box. If the path does not start with '/', the file/directory will be renamed relative to the working directory. If the oldPath does not exist, the rename will fail.
  - `newPath` string, required — New path in the box. If the path does not start with '/', the file/directory will be renamed relative to the working directory. If the newPath already exists, the rename will fail.

## Response `200`

Rename file

- union
  - File — File system file representation
    - `type` 'file', required — File type indicator
    - `name` string, required — Name of the file
    - `path` string, required — Full path to the file in the box
    - `size` string, required — Size of the file
    - `mode` string, required — File metadata
    - `lastModified` string, date-time, required — Last modified time of the file
  - Dir — File system directory representation
    - `type` 'dir', required — Directory type indicator
    - `name` string, required — Name of the directory
    - `path` string, required — Full path to the directory in the box
    - `mode` string, required — Directory metadata
    - `lastModified` string, date-time, required — Last modified time of the directory

## Other responses

- `404` — Old path not found
- `409` — New path is already exists

---

[API](https://skmtc.dev/babelcloud/apis/gbox-open-api.md) · [All operations](https://skmtc.dev/babelcloud/apis/gbox-open-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/babelcloud/gbox-open-api/revisions/d655577fa915/schema)
