May 19, 2021 WeChat Mini Program Development Document
Base library 1.9.9 starts to be supported, and low versions need to be compatible.
The file manager
Determine if a file/directory exists
Property | Type | The default | Required | Description |
---|---|---|---|---|
path | string | Is | File/directory path to determine whether it exists (local path) | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail no such file or directory ${path} | The file/directory does not exist |
FileSystemManager.access Synchronization Version
To determine if there is a file / directory path (local path)
error code | Error message | illustrate |
---|---|---|
fail no such file or directory ${path} | File / directory does not exist |
Bastronomy 2.1.0 began support, low version needs to do Compatibility 。
Add content at the end of the file
Property | Type | The default | Required | Description |
---|---|---|---|---|
filePath | string | Is | File path to append content (local path) | |
data | string/ArrayBuffer | Is | Text or binary data to append | |
encoding | string | utf8 | Whether | Specifies the character encoding to be written to the file |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
The legal value of object.encoding
Value | Description | The lowest version |
---|---|---|
Ascii | ||
base64 | ||
binary | ||
hex | ||
ucs2 | Read in small-end order | |
ucs-2 | Read in small-end order | |
utf16le | Read in small-end order | |
utf-16le | Read in small-end order | |
utf-8 | ||
utf8 | ||
latin1 |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail no such file or directory, open ${filePath} | The specified filePath file does not exist | |
fail illegal operation on a directory, open "${filePath}" | The filePath specified is an existing directory | |
fail permission denied, open ${dirPath} | The specified filePath path does not have write permissions | |
fail sdcard not mounted | The filePath specified is an existing directory |
Base library 2.1.0 starts to support, and low versions need to be compatible.
A synchronized version of FileSystemManager.appendFile
File path to append content (local path)
Text or binary data to append
Specifies the character encoding to be written to the file
The legal value of encoding
Value | Description | The lowest version |
---|---|---|
Ascii | ||
base64 | ||
binary | ||
hex | ||
ucs2 | Read in small-end order | |
ucs-2 | Read in small-end order | |
utf16le | Read in small-end order | |
utf-16le | Read in small-end order | |
utf-8 | ||
utf8 | ||
latin1 |
Error code | The error message | Description |
---|---|---|
fail no such file or directory, open ${filePath} | The specified filePath file does not exist | |
fail illegal operation on a directory, open "${filePath}" | The filePath specified is an existing directory | |
fail permission denied, open ${dirPath} | The specified filePath path does not have write permissions | |
fail sdcard not mounted | The filePath specified is an existing directory |
Copy the file
Property | Type | The default | Required | Description |
---|---|---|---|---|
srcPath | string | Is | The source file path, which supports the local path | |
destPath | string | Is | The target file path, which supports the local path | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail permission denied, copyFile ${srcPath} -> ${destPath} | The specified target file path does not have write permissions | |
fail no such file or directory, copyFile ${srcPath} -> ${destPath} | The source file does not exist, or the upper directory of the target file path does not exist | |
fail the maximum size of the file storage limit is exceeded | There is not enough storage space |
A synchronized version of FileSystemManager.copyFile
The source file path, which supports the local path
The target file path, which supports the local path
Error code | The error message | Description |
---|---|---|
fail permission denied, copyFile ${srcPath} -> ${destPath} | The specified target file path does not have write permissions | |
fail no such file or directory, copyFile ${srcPath} -> ${destPath} | The source file does not exist, or the upper directory of the target file path does not exist | |
fail the maximum size of the file storage limit is exceeded | There is not enough storage space |
Gets the local temporary file or local cache file information under the small program
Property | Type | The default | Required | Description |
---|---|---|---|---|
filePath | string | Is | File path to read (local path) | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
size | number | File size, in bytes |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail file not exist | The specified filePath could not find the file |
Gets a list of local cached files saved under the small program
Property | Type | The default | Required | Description |
---|---|---|---|---|
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
fileList | Array.<Object> | An array of files |
The structure of res.fileList
Property | Type | Description |
---|---|---|
filePath | string | File path (local path) |
size | number | The local file size, in bytes |
createTime | number | The timestamp at the time the file was saved, from 1970/01/01 08:00:00 to the number of seconds of the current time |
Create a directory
Property | Type | The default | Required | Description | The lowest version |
---|---|---|---|---|---|
dirPath | string | Is | Directory path created (local path) | ||
recursive | boolean | false | Whether | Whether to create the directory after recursively creating the parent directory of the directory. I f the corresponding parent directory already exists, the parent directory is not created. If dirPath is a/b/c/d and recursive is true, an a directory is created, then a directory is created under directory a, and so on, until the d directory under the a/b/c directory is created. | 2.3.0 |
success | function | Whether | The interface calls a successful callback function | ||
fail | function | Whether | The interface calls the failed callback function | ||
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail no such file or directory ${dirPath} | The parent directory does not exist | |
fail permission denied, open ${dirPath} | The specified filePath path does not have write permissions | |
fail file already exists ${dirPath} | There is a file or directory with the same name |
A synchronized version of FileSystemManager.mkdir
Directory path created (local path)
The base library 2.3.0 starts to support, and the lower version needs to be compatible.
Whether to create the directory after recursively creating the parent directory of the directory. I f the corresponding parent directory already exists, the parent directory is not created. If dirPath is a/b/c/d and recursive is true, an a directory is created, then a directory is created under directory a, and so on, until the d directory under the a/b/c directory is created.
Error code | The error message | Description |
---|---|---|
fail no such file or directory ${dirPath} | The parent directory does not exist | |
fail permission denied, open ${dirPath} | The specified filePath path does not have write permissions | |
fail file already exists ${dirPath} | There is a file or directory with the same name |
Read the list of files in the directory
Property | Type | The default | Required | Description |
---|---|---|---|---|
dirPath | string | Is | Directory path to read (local path) | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
files | Array.<string> | Specify an array of file names in the directory. |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail no such file or directory ${dirPath} | The directory does not exist | |
fail not a directory ${dirPath} | DirPath is not a directory | |
fail permission denied, open ${dirPath} | The specified filePath path does not have read permissions |
A synchronized version of FileSystemManager.readdir
Directory path to read (local path)
Specify an array of file names in the directory.
Error code | The error message | Description |
---|---|---|
fail no such file or directory ${dirPath} | The directory does not exist | |
fail not a directory ${dirPath} | DirPath is not a directory | |
fail permission denied, open ${dirPath} | The specified filePath path does not have read permissions |
Read the contents of the local file
Property | Type | The default | Required | Description | The lowest version |
---|---|---|---|---|---|
filePath | string | Is | Path to the file to read (local path) | ||
encoding | string | Whether | Specifies the character encoding of the read file, and if encoding is not passed, the binary content of the file is read in ArrayBuffer format | ||
position | string | Whether | Read from the file's specified location, or, if not, from the file header. T he range of the read should be the left-closed-right open interval . E ffective range: s0, fileLength - 1. Unit: byte | 2.10.0 | |
length | string | Whether | Specify the length of the file and, if not, read to the end of the file. E ffective range: s1, fileLength. Unit: byte | 2.10.0 | |
success | function | Whether | The interface calls a successful callback function | ||
fail | function | Whether | The interface calls the failed callback function | ||
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
The legal value of object.encoding
Value | Description | The lowest version |
---|---|---|
Ascii | ||
base64 | ||
binary | ||
hex | ||
ucs2 | Read in small-end order | |
ucs-2 | Read in small-end order | |
utf16le | Read in small-end order | |
utf-16le | Read in small-end order | |
utf-8 | ||
utf8 | ||
latin1 |
Property | Type | Description |
---|---|---|
data | string/ArrayBuffer | The contents of the file |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail no such file or directory, open ${filePath} | The directory where the specified filePath is located does not exist | |
fail permission denied, open ${dirPath} | The specified filePath path does not have read permissions |
A synchronized version of FileSystemManager.readFile
Path to the file to read (local path)
Specifies the character encoding of the read file, and if encoding is not passed, the binary content of the file is read in ArrayBuffer format
The legal value of encoding
Value | Description | The lowest version |
---|---|---|
Ascii | ||
base64 | ||
binary | ||
hex | ||
ucs2 | Read in small-end order | |
ucs-2 | Read in small-end order | |
utf16le | Read in small-end order | |
utf-16le | Read in small-end order | |
utf-8 | ||
utf8 | ||
latin1 |
Base library 2.10.0 starts to support, and low versions need to be compatible.
Read from the file's specified location, or, if not, from the file header. T he range of the read should be the left-closed-right open interval . E ffective range: s0, fileLength - 1. Unit: byte
Base library 2.10.0 starts to support, and low versions need to be compatible.
Specify the length of the file and, if not, read to the end of the file. E ffective range: s1, fileLength. Unit: byte
The contents of the file
Error code | The error message | Description |
---|---|---|
fail no such file or directory, open ${filePath} | The directory where the specified filePath is located does not exist | |
fail permission denied, open ${dirPath} | The specified filePath path does not have read permissions |
Delete the local cache files that have been saved under the small program
Property | Type | The default | Required | Description |
---|---|---|---|---|
filePath | string | Is | File paths that need to be deleted (local paths) | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail file not exist | The specified tempFilePath could not find the file |
Rename the file. You can move files from oldPath to newPath
Property | Type | The default | Required | Description |
---|---|---|---|---|
oldPath | string | Is | The source file path, which supports the local path | |
newPath | string | Is | The new file path supports the local path | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail permission denied, rename ${oldPath} -> ${newPath} | The specified source 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 target file path does not exist |
A synchronized version of FileSystemManager.rename
The source file path, which supports the local path
The new file path supports the local path
Error code | The error message | Description |
---|---|---|
fail permission denied, rename ${oldPath} -> ${newPath} | The specified source 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 target file path does not exist |
Delete the directory
Property | Type | The default | Required | Description | The lowest version |
---|---|---|---|---|---|
dirPath | string | Is | Directory path to delete (local path) | ||
recursive | boolean | false | Whether | Whether to recursively delete the directory. If true, the directory and all subdirections and files under that directory are deleted. | 2.3.0 |
success | function | Whether | The interface calls a successful callback function | ||
fail | function | Whether | The interface calls the failed callback function | ||
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail no such file or directory ${dirPath} | The directory does not exist | |
fail directory not empty | The directory is not empty | |
fail permission denied, open ${dirPath} | The specified dirPath path does not have write permissions |
A synchronized version of FileSystemManager.rmdir
Directory path to delete (local path)
The base library 2.3.0 starts to support, and the lower version needs to be compatible.
Whether to recursively delete the directory. If true, the directory and all subdirections and files under that directory are deleted.
Error code | The error message | Description |
---|---|---|
fail no such file or directory ${dirPath} | The directory does not exist | |
fail directory not empty | The directory is not empty | |
fail permission denied, open ${dirPath} | The specified dirPath path does not have write permissions |
Save temporary files locally. This interface moves the temporary file, so when the call is successful, tempFilePath will not be available.
Property | Type | The default | Required | Description |
---|---|---|---|---|
tempFilePath | string | Is | Temporary storage file path (local path) | |
filePath | string | Whether | File path to store (local path) | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
savedFilePath | string | Stored file path (local path) |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail tempFilePath file not exist | The specified tempFilePath could not find the file | |
fail permission denied, open "${filePath}" | The specified filePath path does not have write permissions | |
fail no such file or directory "${dirPath}" | The parent directory does not exist | |
fail the maximum size of the file storage limit is exceeded | There is not enough storage space |
A synchronized version of FileSystemManager.saveFile
Temporary storage file path (local path)
File path to store (local path)
Stored file path (local path)
Error code | The error message | Description |
---|---|---|
fail tempFilePath file not exist | The specified tempFilePath could not find the file | |
fail permission denied, open "${filePath}" | The specified filePath path does not have write permissions | |
fail no such file or directory "${dirPath}" | The parent directory does not exist | |
fail the maximum size of the file storage limit is exceeded | There is not enough storage space |
Gets the file Stats object
Property | Type | The default | Required | Description | The lowest version |
---|---|---|---|---|---|
path | string | Is | File/Directory Path (Local Path) | ||
recursive | boolean | false | Whether | Whether to recursively get Stats information for each file in the directory | 2.3.0 |
success | function | Whether | The interface calls a successful callback function | ||
fail | function | Whether | The interface calls the failed callback function | ||
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
stats | Stats/Object | When recursive is false, res.stats is a Stats object. When recursive is true and path is a path to a directory, res.stats is an Object, the relative path of the key with path as the root path, and value is the Stats object corresponding to that path. |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail permission denied, open ${path} | The specified path path does not have read permissions | |
fail no such file or directory ${path} | The file does not exist |
When the recursive is false
let fs = wx.getFileSystemManager()
fs.stat({
path: `${wx.env.USER_DATA_PATH}/testDir`,
success: res => {
console.log(res.stats.isDirectory())
}
})
When the recursive is true
fs.stat({
path: `${wx.env.USER_DATA_PATH}/testDir`,
recursive: true,
success: res => {
Object.keys(res.stats).forEach(path => {
let stats = res.stats[path]
console.log(path, stats.isDirectory())
})
}
})
A synchronized version of FileSystemManager.stat
File/Directory Path (Local Path)
The base library 2.3.0 starts to support, and the lower version needs to be compatible.
Whether to recursively get Stats information for each file in the directory
When recursive is false, res.stats is a Stats object. When recursive is true and path is a path to a directory, res.stats is an Object, the relative path of the key with path as the root path, and value is the Stats object corresponding to that path.
Error code | The error message | Description |
---|---|---|
fail permission denied, open ${path} | The specified path path does not have read permissions | |
fail no such file or directory ${path} | The file does not exist |
When the recursive is false
let fs = wx.getFileSystemManager()
fs.stat({
path: `${wx.env.USER_DATA_PATH}/testDir`,
success: res => {
console.log(res.stats.isDirectory())
}
})
When the recursive is true
fs.stat({
path: `${wx.env.USER_DATA_PATH}/testDir`,
recursive: true,
success: res => {
Object.keys(res.stats).forEach(path => {
let stats = res.stats[path]
console.log(path, stats.isDirectory())
})
}
})
Delete the file
Property | Type | The default | Required | Description |
---|---|---|---|---|
filePath | string | Is | File path to delete (local path) | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail permission denied, open ${path} | The specified path path does not have read permissions | |
fail no such file or directory ${path} | The file does not exist | |
fail operation not permitted, unlink ${filePath} | The incoming filePath is a directory |
A synchronized version of FileSystemManager.unlink
File path to delete (local path)
Error code | The error message | Description |
---|---|---|
fail permission denied, open ${path} | The specified path path does not have read permissions | |
fail no such file or directory ${path} | The file does not exist | |
fail operation not permitted, unlink ${filePath} | The incoming filePath is a directory |
Unzim the file
Property | Type | The default | Required | Description |
---|---|---|---|---|
zipFilePath | string | Is | The source file path, which supports the local path, can only be zip compressed files | |
targetPath | string | Is | The destination directory path, which supports local paths | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail permission denied, unzip ${zipFilePath} -> ${destPath} | The specified target file path does not have write permissions | |
fail no such file or directory, unzip ${zipFilePath} -> "${destPath} | The source file does not exist, or the upper directory of the target file path does not exist |
Write a file
Property | Type | The default | Required | Description |
---|---|---|---|---|
filePath | string | Is | File path to write to (local path) | |
data | string/ArrayBuffer | Is | The text or binary data to write | |
encoding | string | utf8 | Whether | Specifies the character encoding to be written to the file |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
The legal value of object.encoding
Value | Description | The lowest version |
---|---|---|
Ascii | ||
base64 | ||
binary | ||
hex | ||
ucs2 | Read in small-end order | |
ucs-2 | Read in small-end order | |
utf16le | Read in small-end order | |
utf-16le | Read in small-end order | |
utf-8 | ||
utf8 | ||
latin1 |
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
The legal value of res.err Msg
Value | Description | The lowest version |
---|---|---|
fail no such file or directory, open ${filePath} | The directory where the specified filePath is located does not exist | |
fail permission denied, open ${dirPath} | The specified filePath path does not have write permissions | |
fail the maximum size of the file storage limit is exceeded | There is not enough storage space |
A synchronized version of FileSystemManager.writeFile
File path to write to (local path)
The text or binary data to write
Specifies the character encoding to be written to the file
The legal value of encoding
Value | Description | The lowest version |
---|---|---|
Ascii | ||
base64 | ||
binary | ||
hex | ||
ucs2 | Read in small-end order | |
ucs-2 | Read in small-end order | |
utf16le | Read in small-end order | |
utf-16le | Read in small-end order | |
utf-8 | ||
utf8 | ||
latin1 |
Error code | The error message | Description |
---|---|---|
fail no such file or directory, open ${filePath} | The directory where the specified filePath is located does not exist | |
fail permission denied, open ${dirPath} | The specified filePath path does not have write permissions | |
fail the maximum size of the file storage limit is exceeded | There is not enough storage space |