Skip to content

Renaming a File/Directory

- (void)renameWithPath:(NSString * _Nonnull)path newName:(NSString * _Nonnull)newName responseHandler:^(NSString * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func rename(path: String, newName: String, responseHandler: ((String) -> Void)!, errorHandler: ((Fault) -> Void)!)


Argument                Description
path -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.

Return value

Absolute path of the renamed file or directory.


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

[Backendless.shared.file renameWithPath:@"documentation/readme.txt" newName:@"readme-first.txt" responseHandler:^(NSString *filePath) {
    NSLog(@"File has been renamed: %@", filePath);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
Backendless.shared.file.rename(path: "documentation/readme.txt", newName: "readme-first.txt", responseHandler: { filePath in
    print("File has been renamed: \(filePath)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")


The server may return the following errors:

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

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