Skip to content

Renaming a File/Directory


Methods:
Blocking API

public string RenameFile( String oldPathName, String newName )

Non-Blocking API

public void RenameFile( String oldPathName, String newName, AsyncCallback<string> responder )

where:

Argument                Description
oldPathName a path identifying file or directory to be renamed. The must start with the root directory for the file storage allocated to the application.
newName new name for the file or directory.
responder A responder object which receives a callback when the method successfully completes or if an error occurs. Applies to the asynchronous methods only.

Return value

Absolute path of the renamed file or directory.

Example

The example below describes how to rename a file called readme.txt located in the /documentation directory to readme-first.txt:

Backendless.Files.RenameFile( "/documentation/readme.txt", "readme-first.txt" );

Errors

The server may return the following errors:

Error Code
Error message
Notes
4000
User has no permissions to specified resource
Occurs when the user (anonymous or logged in) has no permission to modify the file
6000
File or directory cannot be found.
Occurs when the source file/directory cannot be found.
6006
Path contains prohibited symbols: {path name}

6007
The specified resource was not found
Occurs when the API requests to rename a non-existent file or a directory.
6018
Unable to modify file/folder: file/folder already exists: {file/directory name}
Occurs when the target file/directory already exists.
6028
Parameter {param name} cannot be null
Occurs when one of the parameters is null.
8010
Missing field {field name}
Occurs in REST APIs when one of the required fields is missing in the body.

Codeless Reference

files_api_rename_file_directotry_1

where:

Argument                Description
current path A path identifying file or directory to be renamed. The path must start with the root directory of the remote file storage.
new name New name for the file or directory.
return URL of the renamed directory/file When this box is checked, the operation returns a URL to the renamed file or directory.

Returns the URL to the renamed file or directory

Consider the following file stored in the notes directory:

files_api_rename_file_directotry_2

The example below renames the "grocery.txt" file to "buy_food.txt". The same operation can be also applied to a folder, not only to a file.

files_api_rename_file_directotry_3

The result of this operation will look as shown below after the Codeless logic runs:

files_api_rename_file_directotry_4