小程序开放平台

文档中心
暂无目录

xhs.copyFile

更新时间:2024-11-14 11:47:48

以 Promise 风格 调用:不支持

功能描述

复制文件

参数

Object object

属性
类型
默认值
必填
说明
srcPathstring是源文件路径,支持本地路径
destPathstring是目标文件路径,支持本地路径
successfunction否接口调用成功的回调函数
failfunction否接口调用失败的回调函数
completefunction否接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

const fs = xhs.getFileSystemManager()
fs.copyFile({
  srcPath: `${xhs.env.USER_DATA_PATH}/hello.txt`,
  destPath: `${xhs.env.USER_DATA_PATH}/hello_copy.txt`
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})

// 同步接口
try {
  fs.copyFileSync(
    `${xhs.env.USER_DATA_PATH}/hello.txt`,
    `${xhs.env.USER_DATA_PATH}/hello_copy.txt`
  )
} catch(e) {
  console.error(e)
}
该文档是否对您有帮助?