# FileSystemManager.rename(Object object)
with Promise style call: Not supported
Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2
Rename the file. You can transfer files from oldPath Move to newPath
# parameter
# Object object
attribute | type | Default values | Required | Introductions |
---|---|---|---|---|
oldPath | string | yes | Source file path, support local path | |
newPath | string | yes | New file path, support local path | |
success | function | no | Interface calls the successful callback function | |
fail | function | no | Interface calls failed callback functions | |
complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) |
# object.fail callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
errMsg | string | Error message |
res.errMsg Legal value
value | Introductions | Minimum version |
---|---|---|
fail permission denied, rename ${oldPath} -> ${newPath} | Specifies that the source file or destination file does not have write permissions | |
fail No such file or directory, rename ${oldPath} -> ${newPath} | The source file does not exist or the upper directory of the destination file path does not exists |
# sample code
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)
}
})
// Synchronous interface
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)
}