# FileSystemManager.copyFile(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
Copy file
# parameter
# Object object
| attribute | type | Default values | Required | Introductions |
|---|---|---|---|---|
| srcPath | string | yes | Source file path, support local path | |
| destPath | string | yes | Destination file path, local path support | |
| 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, copyFile ${srcPath} -> ${destPath} | Specify destination file path without write permissions | |
| fail No such file or directory, copyFile ${srcPath} -> ${destPath} | The source file does not exist or the upper directory of the destination file path does not exists | |
| fail the maximum size of the file storage limit is exceeded | Insufficient storage space | |
| fail sdcard not mounted | Android sdcard Mount failure |
# sample code
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)
}
})
// Synchronous interface
try {
fs.copyFileSync(
`${wx.env.USER_DATA_PATH}/hello.txt`,
`${wx.env.USER_DATA_PATH}/hello_copy.txt`
)
} catch(e) {
console.error(e)
}