FileSystemManager.rename
Introduction
This function is used to rename a file. It can move a file from the oldPath to the newPath.
Usage Restrictions
This feature is supported in Basic Library version 3.0.0 or higher.
Parameters
Object object
| Attribute | Type | Default Value | Required | Description |
|---|---|---|---|---|
| oldPath | string | Yes | Source file path, supports relative paths | |
| newPath | string | Yes | New file path, supports local paths | |
| success | function | No | Callback function when the API call is successful | |
| fail | function | No | Callback function when the API call fails | |
| complete | function | No | Callback function when the API call ends (executed regardless of success or failure) |
object.success
Callback Function
Parameters
Object res
| Attribute | Type | Description |
|---|---|---|
| success | string | true - success |
object.fail
Callback Function
Parameters
Object res
| Attribute | Type | Description |
|---|---|---|
| errMsg | string | Error message |
| success | string | false - failure |
errMsg Description
| Error message | Description |
|---|---|
| parameter error: F10001 | Invalid parameter |
| fail sdcard not mounted: F10002 | Android sdcard mounting failed |
| fail permission denied: F10005, rename ${oldPath} -> ${newPath} | Source file or target file does not have write permission |
| fail no such file or directory: F10007, rename ${oldPath} -> ${newPath} | Source file does not exist or the parent directory of the target file path does not exist |
Sample Code
// pages/index/index.js
Page({
rename() {
const fs = dlt.getFileSystemManager();
fs.rename({
oldPath: `${dlt.env.USER_DATA_PATH}/hello.txt`,
newPath: `${dlt.env.USER_DATA_PATH}/hello_new.txt`,
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});