fileSystemManager.copyFile
基础库 1.15.0 开始支持本方法,低版本需做兼容处理。
复制文件。
语法
fileSystemManager.copyFile(options)
参数说明
options
options 为 object 类型, 说明如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
srcPath | string | 是 | 源文件路径,只可以是普通文件 | 1.15.0 | |
destPath | string | 是 | 目标文件路径, 必须以 ttfile://user 开头 | 1.15.0 | |
success | Function | 否 | 接口调用成功的回调函数 | 1.15.0 | |
fail | Function | 否 | 接口调用失败的回调函数 | 1.15.0 | |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 1.15.0 |
回调成功
属性 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | 1.15.0 |
回调失败
属性 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "copyFile:fail" + 详细错误信息 | 1.15.0 |
详细错误信息 | 说明 |
---|---|
"fail permission denied" | 指定目标文件路径没有写权限 |
"fail no such file or directory" | 源文件不存在,或目标文件路径的上层目录不存在 |
代码示例
const fileSystemManager = tt.getFileSystemManager();
Page({
onReady() {
fileSystemManager.copyFile({
srcPath,
destPath,
success(_res) {
console.log("拷贝成功");
},
fail(res) {
console.log("拷贝失败", res.errMsg);
},
});
},
});
Bug & Tip
无
点击纠错
评价此篇文档