FileSystemManager.copyFile
收藏
我的收藏

基础库 1.15.0 开始支持本方法,这是一个异步方法。

复制文件。

前提条件
业务背景
使用限制
注意事项
每个小程序的用户目录存储上限为 10M,不同小程序的用户目录相互隔离。
支持沙盒
相关教程

语法

FileSystemManager.copyFile(options)

参数说明

options 为 object 类型,属性如下:

属性名类型默认值必填说明最低支持版本
srcPathstring
源文件路径,只可以是普通文件
1.15.0
destPathstring
目标文件路径, 必须以 `ttfile://user` 开头
1.15.0
successfunction
接口调用成功的回调函数
1.15.0
failfunction
接口调用失败的回调函数
1.15.0
completefunction
接口调用结束的回调函数(调用成功、失败都会执行)
1.15.0

回调成功

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
"copyFile:ok"
1.15.0

回调失败

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
"copyFile:fail" + 详细错误信息
1.15.0

错误码

errNoerrMsg说明最低支持版本
20000copyFile:fail srcPath is invalid
srcPath 参数错误
1.99.0
20000copyFile:fail destPath is invalid
destPath 参数错误
1.99.0
21101copyFile:fail permission denied, copyFile %s -> %s
无操作权限(源路径不可读/目标路径不可写)
1.99.0
21102copyFile:fail operation not permitted, copyFile %s
path 类型不是文件
1.99.0
21103copyFile:fail no such file or directory, copyFile %s -> %s
文件不存在
1.99.0
21104copyFile:fail user dir saved file size limit exceeded
超出 User 目录存储上限
1.99.0

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

const fileSystemManager = tt.getFileSystemManager()

Page({
  onReady() {
    fileSystemManager.copyFile({
      srcPath,
      destPath,
      success(_res) {
        console.log("拷贝成功")
      },
      fail(res) {
        console.log("拷贝失败", res.errMsg)
      },
    })
  },
})