Called in Promise style: Not supported
Mini Program Plugin: Supported, requires Mini Program base library version not lower than 2.19.2
WeChat HarmonyOS Edition: Supported
Related documentation: File System
Feature Description
Synchronous version of FileSystemManager.copyFile
Parameters
string srcPath
The path to the source file. Local paths are supported.
string destPath
Destination file path. Local paths are supported.
Error
| Error Code | Error Message | Description |
|---|---|---|
| 1300001 | operation not permitted | Operation not permitted (e.g., filePath expects a file but a directory was actually provided) |
| 1300002 | no such file or directory ${path} | File/directory does not exist, or the parent directory of the target file path does not exist |
| 1300005 | Input/output error | Input/output stream is unavailable |
| 1300009 | bad file descriptor | Invalid file descriptor |
| 1300013 | permission denied | Permission error; the file is read-only or write-only |
| 1300014 | Path permission denied | No permission for the provided path |
| 1300020 | not a directory | The path specified by dirPath is not a directory; this commonly occurs when the parent path of the specified write path is a file |
| 1300021 | Is a directory | The specified path is a directory |
| 1300022 | Invalid argument | Invalid argument; check whether length or offset is out of bounds |
| 1300036 | File name too long | File name is too long |
| 1300066 | directory not empty | Directory is not empty |
| 1300201 | system error | Failed to call system interface |
| 1300202 | the maximum size of the file storage limit is exceeded | Insufficient storage space, or file size exceeds the limit (limit is 100MB) |
| 1300203 | base64 encode error | Character encoding conversion failed (e.g., incorrect base64 format) |
| 1300300 | sdcard not mounted | Android SD card mount failed |
| 1300301 | unable to open as fileType | Unable to open file as fileType |
| 1301000 | permission denied, cannot access file path | No access permission to the target path (usr directory) |
| 1301002 | data to write is empty | Data to write is empty |
| 1301003 | illegal operation on a directory | This operation is not allowed on a directory (e.g., the specified filePath is an existing directory) |
| 1301004 | illegal operation on a package directory | This operation is not allowed on the code package directory |
| 1301005 | file already exists ${dirPath} | A file or directory with the same name already exists |
| 1301006 | value of length is out of range | The provided length is invalid |
| 1301007 | value of offset is out of range | The provided offset is invalid |
| 1301009 | value of position is out of range | position value is out of bounds |
| 1301100 | store directory is empty | Store directory is empty |
| 1301102 | unzip open file fail | Failed to open the compressed file |
| 1301103 | unzip entry fail | Failed to extract a single file |
| 1301104 | unzip fail | Extraction failed |
| 1301111 | brotli decompress fail | Brotli decompression failed (e.g., the specified compressionAlgorithm does not match the actual compression format of the file) |
| 1301112 | tempFilePath file not exist | File not found at the specified tempFilePath |
| 1302001 | fail permission denied | The specified fd path does not have read/write permission |
| 1302002 | excced max concurrent fd limit | The number of fds has reached the upper limit |
| 1302003 | invalid flag | Invalid flag |
| 1302004 | permission denied when open using flag | Unable to open the file using the specified flag |
| 1302005 | array buffer does not exist | arrayBuffer was not provided |
| 1302100 | array buffer is readonly | arrayBuffer is read-only |
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)
}
})
// 同步接口
try {
fs.copyFileSync(
`${wx.env.USER_DATA_PATH}/hello.txt`,
`${wx.env.USER_DATA_PATH}/hello_copy.txt`
)
} catch(e) {
console.error(e)
}