# FileSystemManager.copyFileSync(string srcPath, string destPath)
以 Promise 风格 调用:不支持
相关文档: 文件系统
# 功能描述
FileSystemManager.copyFile 的同步版本
# 参数
# string srcPath
源文件路径,支持本地路径
# string destPath
目标文件路径,支持本地路径
# 错误
错误码 | 错误信息 | 说明 |
---|---|---|
fail permission denied, copyFile ${srcPath} -> ${destPath} | 指定目标文件路径没有写权限 | |
fail no such file or directory, copyFile ${srcPath} -> ${destPath} | 源文件不存在,或目标文件路径的上层目录不存在 | |
fail the maximum size of the file storage limit is exceeded | 存储空间不足 | |
fail sdcard not mounted | Android sdcard 挂载失败 |
# 示例代码
const fs = wx.getFileSystemManager()
fs.copyFile({
srcPath: `${wx.env.USER_DATA_PATH}/hello.txt`,
destPath: `${wx.env.USER_DATA_PATH}/hello_copy.txt`
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})
// 同步接口
try {
fs.copyFileSync(
`${wx.env.USER_DATA_PATH}/hello.txt`,
`${wx.env.USER_DATA_PATH}/hello_copy.txt`
)
} catch(e) {
console.error(e)
}