FileSystemManager.copyFile
Introduction
Copies a file.
Usage Restrictions
Requires basic library version 3.0.0 or higher.
Parameters
Object object
| Property | Type | Default | Required | Description |
|---|---|---|---|---|
| srcPath | string | Yes | Source file path (relative path) | |
| destPath | string | Yes | Destination file path (relative path) | |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function called after API call completion (executed regardless of success or failure) |
object.success Callback Function
Parameters
Object res
| Property | Type | Description |
|---|---|---|
| success | string | true-Successful |
object.fail Callback Function
Parameters
Object res
| Property | Type | Description |
|---|---|---|
| errMsg | string | Error message |
| success | string | false-Failed |
errMsg Description
| Error message | Explanation |
|---|---|
| parameter error: F10001 | Source path or destination path parameter is null |
| fail sdcard not mounted: F10002 | Android sdcard mount failed |
| fail the maximum size of the file storage limit exceeded: F10004 | Insufficient storage space |
| fail permission denied: F10005, copyFile ${srcPath} -> ${destPath} | Copy failed, specified destination file path does not have write permission |
| fail no such file or directory: F10007, copyFile ${srcPath} -> ${destPath} | Source file does not exist, or the parent directory of the destination file path does not exist |
Sample Code
// pages/index/index.js
Page({
copyFile() {
const fs = dlt.getFileSystemManager();
fs.copyFile({
srcPath: `${dlt.env.USER_DATA_PATH}/hello.txt`,
destPath: `${dlt.env.USER_DATA_PATH}/hello_copy.txt`,
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});