# FileSystemManager.renameSync(string oldPath, string newPath)
with Promise style call: Not supported
Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2
FileSystemManager.rename The synchronous version of
# parameter
# string oldPath
Source file path, support local path
# string newPath
New file path, support local path
# error
Error code | Error message | Introductions |
---|---|---|
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)
}
The translations are provided by WeChat Translation and are for reference only. In case of any inconsistency and discrepancy between the Chinese version and the English version, the Chinese version shall prevail.Incorrect translation. Tap to report.