Moving a file or folder

To move files and folders on Yandex Disk, specify the current path to the resource and its new location.

Request format

Use the POST method to send the move request.

https://cloud-api.yandex.net/v1/disk/resources/move
 ? from=<path to the resource that you want to move>
 & path=<new path to the resource>
 & [overwrite=<overwrite flag>]
 & [fields=<properties to include in the response>]
from*

The path to the resource being moved. For example, %2Ffoo%2Fphoto.png.

The path in the parameter value should be encoded in URL format.

path*

The path to the new location of the resource. For example, %2Fbar%2Fphoto.png (maximum path length is 32760 characters).

The path in the parameter value should be encoded in URL format.

overwrite

File overwrite flag. Used if the resource is moved to a folder that already contains a resource with the same name.

Supported values:

  • false: don't overwrite the files and cancel moving. Used by default.
  • true: move the resource and delete the existing file with the same name.
fields
List of JSON properties to include in the response. Keys not specified in this list are omitted when generating a response. If the parameter isn't specified, the response is returned in full without omitting anything.

Key names should be separated by commas, and embedded keys should be separated by dots. For example: name,_embedded.items.path.

* Required parameter.

Response format

If the request is processed without errors, the API creates the response body based on the type of the specified resource. The response for an empty folder or file is different from the response for a non-empty folder.

If the request caused an error, the relevant response code is returned, and the response body contains an error description.

File or empty folder

The API returns the 201 Created code (resource successfully moved). The Link object in the response body contains a link to meta information of the created resource.

Sample response:

{
  "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png",
  "method": "GET",
  "templated": false
}

Non-empty folder

Moving a non-empty folder can take some time, so the API returns the 202 Accepted code (moving started).

Apps must track the status of requested operations. The API returns a link to the status of the requested operation in the response body within the Link object.

Sample response:

{
  "href": "https://cloud-api.yandex.net/v1/disk/operations?id=33ca7d03ab21ct41b4a40182e78d828a3f8b72cdb5f4c0e94cc4b1449a63a2fe",
  "method": "GET",
  "templated": false
}

Element

Description

href

URL. It may be a URL template. See the templated key.

method

The HTTP method for requesting the URL from the href key.

templated

Indicates a URL template according to RFC 6570. Possible values:

  • "true" — URL template. To send a request to this address, replace the placeholder values in the curly brackets with the parameter values.
  • "false" — The URL can be requested without changes.