# FileSystemManager.renameSync(string oldPath, string newPath)
以 Promise 风格 调用:不支持
小程序插件:支持,需要小程序基础库版本不低于 2.19.2
相关文档: 文件系统
# 功能描述
FileSystemManager.rename 的同步版本
# 参数
# string oldPath
源文件路径,支持本地路径
# string newPath
新文件路径,支持本地路径
# 错误
错误码 | 错误信息 | 说明 |
---|---|---|
fail permission denied, rename ${oldPath} -> ${newPath} | 指定源文件或目标文件没有写权限 | |
fail no such file or directory, rename ${oldPath} -> ${newPath} | 源文件不存在,或目标文件路径的上层目录不存在 |
# 示例代码
const fs = wx.getFileSystemManager()
fs.rename({
oldPath: `${wx.env.USER_DATA_PATH}/hello.txt`,
newPath: `${wx.env.USER_DATA_PATH}/hello_new.txt`,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})
// 同步接口
try {
const res = fs.renameSync(
`${wx.env.USER_DATA_PATH}/hello.txt`,
`${wx.env.USER_DATA_PATH}/hello_new.txt`
)
console.log(res)
} catch(e) {
console.error(e)
}