FileSystemManager.copyFile
简介
复制文件。
使用限制
基础库 3.0.0 或更高版本支持。
参数
Object object
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| srcPath | string | 是 | 源文件路径 (相对路径) | |
| destPath | string | 是 | 目标文件路径 (相对路径) | |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数
参数
Object res
| 属性 | 类型 | 说明 |
|---|---|---|
| success | string | true-成功 |
object.fail 回调函数
参数
Object res
| 属性 | 类型 | 说明 |
|---|---|---|
| errMsg | string | 错误信息 |
| success | string | false-失败 |
errMsg 说明
| 错误信息 | 说明 |
|---|---|
| parameter error: F10001 | 原路径或目标路径参数为 null |
| fail sdcard not mounted: F10002 | Android sdcard 挂载失败 |
| fail the maximum size of the file storage limit exceeded: F10004 | 存储空间不足 |
| fail permission denied: F10005, copyFile ${srcPath} -> ${destPath} | 复制失败,指定目标文件路径没有写权限 |
| fail no such file or directory: F10007, copyFile ${srcPath} -> ${destPath} | 源文件不存在,或目标文件路径的上层目录不存在 |
示例代码
// 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);
},
});
},
});