This API is called using wx.saveFile(Object object).
Property | Type | Default value | Required | Description |
tempFilePath | string | - | True | The temporary path of the file to be saved. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
savedFilePath | string | The path of the file after saving. |
wx.chooseImage({success(res) {const tempFilePaths = res.tempFilePathswx.saveFile({tempFilePath: tempFilePaths[0],success(res) {const savedFilePath = res.savedFilePath}})}})
This API is called using wx.removeSavedFile(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | The path to the file that needs to be deleted. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.getSavedFileList({success(res) {if (res.fileList.length > 0) {wx.removeSavedFile({filePath: res.fileList[0].filePath,complete(res) {console.log(res)}})}}})
This API is called using wx.openDocument(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | The file path (local path), which can be obtained via downloadFile. |
fileType | string | - | False | The type of the file, used to specify the file type for opening. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
pdf | PDF format. |
wx.downloadFile({// Example URL, not a real fileurl: 'https://example.com/somefile.pdf',success(res) {const filePath = res.tempFilePathwx.openDocument({filePath,success(res) {console.log('Document opened successfully')}})}})
This API is called using wx.getSavedFileList(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
fileList | Array.<Object> | Array of files, each item is a FileItem. |
Property | Type | Description |
filePath | string | Local path. |
size | number | Local file size in bytes. |
createTime | number | Timestamp when the file was saved, in seconds since 1970/01/01 08:00:00 |
wx.getSavedFileList({success(res) {console.log(res.fileList)}})
This API is called using wx.getSavedFileInfo(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | File path. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
size | number | File size in bytes. |
createTime | number | Timestamp when the file was saved, in seconds since 1970/01/01 08:00:00 |
wx.getSavedFileList({success(res) {console.log(res.fileList)}})
This API is called using wx.getFileInfo(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | Local file path. |
digestAlgorithm | string | 'md5' | False | The algorithm used to calculate the file digest. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
md5 | The MD5 algorithm. |
sha1 | The SHA1 algorithm. |
Property | Type | Description |
size | number | The file size in bytes. |
digest | string | File digest calculated using the specified algorithm. |
wx.getFileInfo({success(res) {console.log(res.size)console.log(res.digest)}})
This API is called using FileSystemManager wx.getFileSystemManager().
This method is called using FileSystemManager.access(Object object).
Property | Type | Default value | Required | Description |
path | string | - | True | The path of the file or directory to check for existence. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail no such file or directory ${path} | The file or directory does not exist. |
bad file descriptor | Invalid file descriptor. |
permission denied | Permission error. The file is read-only or write-only. |
permission denied, cannot access file path | No access to the target path (e.g., usr directory) |
not a directory | The specified path is not a directory |
Invalid argument | Invalid argument, check if length or offset is out of range. |
directory not empty | The directory is not empty. |
the maximum size of the file storage limit is exceeded | Storage space is insufficient, or file size exceeds the limit (100 MB). |
base64 encode error | Character encoding conversion failed (e.g., incorrect base64 format). |
data to write is empty | The data to write is empty. |
illegal operation on a directory | Illegal operation on a directory (e.g., specified filePath is an existing directory). |
file already exists ${dirPath} | A file or directory with the same name already exists. |
value of length is out of range | The length value is out of range. |
value of offset is out of range | The offset value is out of range. |
value of position is out of range | The position value is out of range. |
const fs = wx.getFileSystemManager()// Determine whether a file or directory existsfs.access({path: `${wx.env.USER_DATA_PATH}/hello.txt`,success(res) {// The file existsconsole.log(res)},fail(res) {// File does not exist or other errorconsole.error(res)}})// Synchronous APItry {fs.accessSync(`${wx.env.USER_DATA_PATH}/hello.txt`)} catch(e) {console.error(e)}
This method is called using FileSystemManager.accessSync(string path).
const fs = wx.getFileSystemManager()// Determine whether a file or directory existsfs.access({path: `${wx.env.USER_DATA_PATH}/hello.txt`,success(res) {// The file existsconsole.log(res)},fail(res) {// File does not exist or other errorconsole.error(res)}})// Synchronous APItry {fs.accessSync(`${wx.env.USER_DATA_PATH}/hello.txt`)} catch(e) {console.error(e)}
This method is called using FileSystemManager.appendFile(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | Path of the file to append content to. |
data | string/ArrayBuffer | - | True | Text or binary data to append. |
encoding | string | utf-8 | False | Character encoding for writing to the file. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail no such file or directory, open ${filePath} | The specified filePath does not exist. |
fail illegal operation on a directory, open "${filePath}" | The specified filePath is a directory that already exists. |
fail permission denied, open ${dirPath} | No write permission for the specified filePath. |
fail sdcard not mounted | Failed to mount the Android SDCard. |
const fs = wx.getFileSystemManager()fs.appendFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,data: 'some text',encoding: 'utf8',success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {fs.appendFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'some text', 'utf8')} catch(e) {console.error(e)}
This method is called using FileSystemManager.appendFileSync(string filePath, string|ArrayBuffer data, string encoding).
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
const fs = wx.getFileSystemManager()fs.appendFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,data: 'some text',encoding: 'utf8',success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {fs.appendFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'some text', 'utf8')} catch(e) {console.error(e)}
This method is called using FileSystemManager.close(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True | File descriptor to be closed, obtained through FileSystemManager.open or FileSystemManager.openSync. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
const fs = wx.getFileSystemManager()// Open a filefs.open({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+',success(res) {// Close the filefs.close({fd: res.fd})}})
This method is called using FileSystemManager.closeSync(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True | File descriptor to be closed, obtained through FileSystemManager.open or FileSystemManager.openSync. |
const fs = wx.getFileSystemManager()const fd = fs.openSync({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+'})// Close the filefs.closeSync({fd: fd})
This method is called using FileSystemManager.copyFile(Object object).
Property | Type | Default value | Required | Description |
srcPath | string | - | True | Source file path, must be a regular file. |
destPath | string | - | True | Destination file path, supports local paths. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail permission denied, copyFile ${srcPath} -> ${destPath} | No write permission for the destination file path. |
fail no such file or directory, copyFile ${srcPath} -> ${destPath} | Source file does not exist, or the parent directory of the destination file path does not exist. |
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 APItry {fs.copyFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`,`${wx.env.USER_DATA_PATH}/hello_copy.txt`)} catch(e) {console.error(e)}
This method is called using FileSystemManager.copyFileSync(string srcPath, string destPath).
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 APItry {fs.copyFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`,`${wx.env.USER_DATA_PATH}/hello_copy.txt`)} catch(e) {console.error(e)}
This method is called using FileSystemManager.getFileInfo(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | The path of the file to read. |
digestAlgorithm | string | md5 | False | The algorithm used to calculate the file digest. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
md5 | The MD5 algorithm. |
sha1 | The SHA1 algorithm. |
Property | Type | Description |
size | number | The file size in bytes. |
digest | string | File digest calculated using the specified algorithm. |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail file not exist | The specified filePath could not be found. |
no such file or directory ${path} | File/directory does not exist, or the parent directory is missing. |
Input/output error | Input/output stream is unavailable. |
permission denied | Permission error. The file is read-only or write-only. |
Path permission denied | No permission for the specified path. |
not a directory | The specified path is not a directory. |
Invalid argument | Invalid argument, check if length or offset is out of range. |
excced max concurrent fd limit | Maximum number of file descriptors reached. |
This method is called using FileSystemManager.fstat(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True | |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
stats | Stats object containing file status information. |
const fs = wx.getFileSystemManager()// Open a filefs.open({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+',success(res) {// Get status information of the filefs.fstat({fd: res.fd,success(res) {console.log(res.stats)}})}})
This method is called using Stats FileSystemManager.fstatSync(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True |
const fs = wx.getFileSystemManager()const fd = fs.openSync({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+'})const stats = fs.fstatSync({fd: fd})console.log(stats)
This method is called using FileSystemManager.ftruncate(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True | |
length | number | - | True | The truncation position. Default value: 0. If the length is less than the file length (in bytes), only the first length bytes will be remained in the file, and the rest will be deleted. If the length is greater than the file length, the file will be extended, and the extended part will be filled with null bytes ('\\0'). |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
const fs = wx.getFileSystemManager()// Open a filefs.open({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+',success(res) {// Truncate the file contentfs.ftruncate({fd: res.fd,length: 10, // Truncate the file from the 10th bytesuccess(res) {console.log(res)}})}})
This method is called using undefined FileSystemManager.ftruncateSync(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True | |
length | number | - | True | The truncation position. Default value: 0. If the length is less than the file length (in bytes), only the first length bytes will be remained in the file, and the rest will be deleted. If the length is greater than the file length, the file will be extended, and the extended part will be filled with null bytes ('\\0'). |
const fs = wx.getFileSystemManager()const fd = fs.openSync({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+'})fs.ftruncateSync({fd: fd,length: 10 // Truncate the file from the 10th byte})
This method is called using FileSystemManager.getSavedFileList(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
fileList | Array.<Object> | Array of file objects. |
Property | Type | Description |
filePath | string | Local path. |
size | number | Local file size in bytes. |
createTime | number | Timestamp when the file was saved, in seconds since 1970/01/01 08:00:00 |
This method is called using FileSystemManager.mkdir(Object object).
Property | Type | Default value | Required | Description |
dirPath | string | - | True | Path of the directory to create. |
recursive | boolean | false | False | Whether to recursively create the parent directories. If the parent directories already exist, they will not be created. For example, if dirPath is a/b/c/d and recursive is true, it will create directory a, then b inside a, and so on until d inside a/b/c. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail no such file or directory ${dirPath} | The parent directory does not exist. |
fail permission denied, open ${dirPath} | No write permission for the specified filePath. |
fail file already exists ${dirPath} | A file or directory with the same name already exists. |
const fs = wx.getFileSystemManager()fs.mkdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,recursive: false,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {fs.mkdirSync(`${wx.env.USER_DATA_PATH}/example`, false)} catch(e) {console.error(e)}
This method is called using FileSystemManager.mkdirSync(string dirPath, boolean recursive).
const fs = wx.getFileSystemManager()fs.mkdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,recursive: false,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {fs.mkdirSync(`${wx.env.USER_DATA_PATH}/example`, false)} catch(e) {console.error(e)}
This method is called using FileSystemManager.open(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | File path (local path). |
flag | string | r | False | File system flag. Default value: r. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
a | Opens the file for appending. If the file does not exist, it will be created. |
ax | Similar to 'a', but the file opening will fail if the path exists. |
a+ | Opens the file for reading and appending. If the file does not exist, it will be created. |
ax+ | Similar to 'a+', but the file opening will fail if the path exists. |
as | Open file for appending in synchronous mode. If the file does not exist, it will be created. |
as+ | Open file for reading and appending in synchronous mode. If the file does not exist, it will be created. |
r | Opens the file for reading. If the file does not exist, an error will occur. |
r+ | Opens the file for reading and writing. If the file does not exist, an error will occur. |
w | Opens the file for writing. If the file does not exist, create the file; if the file exists, truncate the file. |
wx | Similar to 'w', but the file opening will fail if the path exists. |
w+ | Opens the file for reading and writing. If the file does not exist, create the file; if the file exists, truncate the file. |
wx+ | Similar to 'w+', but the file opening will fail if the path exists. |
Property | Type | Description |
fd | string | File descriptor. |
const fs = wx.getFileSystemManager()fs.open({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+',success(res) {console.log(res.fd)}})
This method is called using string FileSystemManager.openSync(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | File path (local path). |
flag | string | r | False | File system flag. Default value: r. |
Value | Description |
a | Opens the file for appending. If the file does not exist, it will be created. |
ax | Similar to 'a', but the file opening will fail if the path exists. |
a+ | Opens the file for reading and appending. If the file does not exist, it will be created. |
ax+ | Similar to 'a+', but the file opening will fail if the path exists. |
as | Open file for appending in synchronous mode. If the file does not exist, it will be created. |
as+ | Open file for reading and appending in synchronous mode. If the file does not exist, it will be created. |
r | Opens the file for reading. If the file does not exist, an error will occur. |
r+ | Opens the file for reading and writing. If the file does not exist, an error will occur. |
w | Opens the file for writing. If the file does not exist, create the file; if the file exists, truncate the file. |
wx | Similar to 'w', but the file opening will fail if the path exists. |
w+ | Opens the file for reading and writing. If the file does not exist, create the file; if the file exists, truncate the file. |
wx+ | Similar to 'w+', but the file opening will fail if the path exists. |
const fs = wx.getFileSystemManager() const fd = fs.openSync({ filePath: `${wx.env.USER_DATA_PATH}/hello.txt`, flag: 'a+' }) console.log(fd)
This method is called using FileSystemManager.read(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True | |
arrayBuffer | ArrayBuffer | - | True | The buffer to which the data is written, and it must be an instance of ArrayBuffer. |
offset | number | 0 | False | The write offset in the buffer. Default value: 0. |
length | number | 0 | False | The number of bytes to be read in the file. Default value: 0. |
position | number | - | False | The starting position for reading the file. If this property is not provided or null is entered, the file is read from the position of the current file pointer. If the position is a positive integer, the file pointer position remains unchanged and the file is read from the position. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
bytesRead | number | Number of bytes actually read. |
arrayBuffer | ArrayBuffer | The buffer object that was written to, same as the arrayBuffer parameter passed to the API. |
const fs = wx.getFileSystemManager()const ab = new ArrayBuffer(1024)// Open a filefs.open({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+',success(res) {// Read the file into an ArrayBufferfs.read({fd: res.fd,arrayBuffer: ab,length: 10,success(res) {console.log(res)}})}})
This method is called using ReadResult FileSystemManager.readSync(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True | |
arrayBuffer | ArrayBuffer | - | True | The buffer to which the data is written, and it must be an instance of ArrayBuffer. |
offset | number | 0 | False | The write offset in the buffer. Default value: 0. |
length | number | 0 | False | The number of bytes to be read in the file. Default value: 0. |
position | number | - | False | The starting position for reading the file. If this property is not provided or null is entered, the file is read from the position of the current file pointer. If the position is a positive integer, the file pointer position remains unchanged and the file is read from the position. |
const fs = wx.getFileSystemManager()const ab = new ArrayBuffer(1024)const fd = fs.openSync({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+'})const res = fs.readSync({fd: fd,arrayBuffer: ab,length: 10})console.log(res)
This method is called using FileSystemManager.readCompressedFile(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | Path of the file to read (local user file or code package file). |
compressionAlgorithm | string | - | True | File compression type, currently only supports br. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
br | Brotli-compressed file. |
Property | Type | Description |
data | ArrayBuffer | File content. |
const fs = wx.getFileSystemManager()// Asynchronous APIfs.readCompressedFile({filePath: '${wx.env.USER_DATA_PATH}/hello.br',compressionAlgorithm: 'br',success(res) {console.log(res.data)},fail(res) {console.log('readCompressedFile fail', res)}})// Synchronous APIconst data = fs.readCompressedFileSync({filePath: '${wx.env.USER_DATA_PATH}/hello.br',compressionAlgorithm: 'br',})console.log(data)
This method is called using ArrayBuffer FileSystemManager.readCompressedFileSync(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | Path of the file to read (local user file or code package file). |
compressionAlgorithm | string | - | True | File compression type, currently only supports br. |
Value | Description |
br | Brotli-compressed file. |
const fs = wx.getFileSystemManager()// Asynchronous APIfs.readCompressedFile({filePath: '${wx.env.USER_DATA_PATH}/hello.br',compressionAlgorithm: 'br',success(res) {console.log(res.data)},fail(res) {console.log('readCompressedFile fail', res)}})// Synchronous APItry {const data = fs.readCompressedFileSync({filePath: '${wx.env.USER_DATA_PATH}/hello.br',compressionAlgorithm: 'br',})console.log(data)} catch (err) {console.log(err)}
This method is called using FileSystemManager.readdir(Object object).
Property | Type | Default value | Required | Description |
dirPath | string | - | True | The path to the directory to be read. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
files | Array.<string> | An array of filenames in a specified directory. |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail no such file or directory ${dirPath} | The directory does not exist. |
fail not a directory ${dirPath} | The dirPath is not a directory. |
fail permission denied, open ${dirPath} | No read permission for the specified filePath. |
const fs = wx.getFileSystemManager()fs.readdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,success(res) {console.log(res.files)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.readdirSync(`${wx.env.USER_DATA_PATH}/example`)console.log(res)} catch(e) {console.error(e)}
This method is called using Array.<string>FileSystemManager.readdirSync(string dirPath).
const fs = wx.getFileSystemManager()fs.readdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,success(res) {console.log(res.files)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.readdirSync(`${wx.env.USER_DATA_PATH}/example`)console.log(res)} catch(e) {console.error(e)}
This method is called using FileSystemManager.readFile(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | The path to the file to be read. |
encoding | string | - | False | Specify the file's character encoding for reading. If no encoding is provided, the file's binary content will be read as an ArrayBuffer. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Property | Type | Description |
data | string/ArrayBuffer | File content. |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail no such file or directory, open ${filePath} | The specified filePath directory does not exist. |
fail permission denied, open ${dirPath} | No read permission for the specified filePath. |
const fs = wx.getFileSystemManager()fs.readFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,encoding: 'utf8',position: 0,success(res) {console.log(res.data)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.readFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'utf8', 0)console.log(res)} catch(e) {console.error(e)}
This method is called using string|ArrayBuffer FileSystemManager.readFileSync(string filePath, string encoding).
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
const fs = wx.getFileSystemManager()fs.readFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,encoding: 'utf8',position: 0,success(res) {console.log(res.data)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.readFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'utf8', 0)console.log(res)} catch(e) {console.error(e)}
This method is called using FileSystemManager.readZipEntry(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | The path of the zip file to be read (local path). |
encoding | string | - | False | Specifies the character encoding for reading files. This is only effective when the entries value is "all". If entries is "all" and no encoding is provided, the file's binary content will be read as an ArrayBuffer. |
entries | Array.<Object>/'all' | - | True | The list of files within the zip archive to be read (passing "all" means reading all files in the archive). |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Structural property | Type | Default value | Required | Description |
path | string | - | True | The path to the files in the compressed package. |
encoding | string | - | False | Specifies the file's character encoding for reading. If no encoding is provided, the file's binary content will be read as an ArrayBuffer. The valid values are the same as those for encoding. |
position | number | - | False | The position to start reading from within the file. If not specified, reading starts from the beginning. The range should be [position, position+length). Valid range: [0, fileLength - 1]. Unit: byte. |
length | number | - | False | The length of the file to read. If not specified, reads until the end of the file. Valid range: [1, fileLength]. Unit: byte. |
Property | Type | Description |
entries | Object | The result of reading the files. res.entries is an object where the key is the file path and the value is a FileItem object representing the read result. Each FileItem contains data (file content) and errMsg (error message) properties. |
Structural property | Type | Description |
path | string | File path. |
Structural property | Type | Description |
data | string/ArrayBuffer | File content. |
errMsg | string | Error message. |
const fs = wx.getFileSystemManager()// Read one or more files in the zip packagefs.readZipEntry({filePath: 'wxfile://from/to.zip',entries: [{path: 'some_folder/my_file.txt', // File path within the zip packageencoding: 'utf-8', // Specify the file's character encoding for reading. If no encoding is provided, the file's binary content will be read as an ArrayBuffer.position: 0, // The position to start reading from within the file. If not specified, reading starts from the beginning. The range should be [position, position+length). Valid range: [0, fileLength - 1]. Unit: byte.length: 10000, // The length of the file to read. If not specified, reads until the end of the file Valid range: [1, fileLength]. Unit: byte.}, {path: 'other_folder/orther_file.txt', // The path to the files within the zip package}],success(res) {console.log(res.entries)// res.entries === {// 'some_folder/my_file.txt': {// errMsg: 'readZipEntry:ok',// data: 'xxxxxx'// },// 'other_folder/orther_file.txt': {// data: (ArrayBuffer)// }// }},fail(res) {console.log(res.errMsg)},})// Read all files in the zip package Allow specifying a unified encoding. position and length are not allowed to be specified, defaulting to 0 and the file length respectivelyfs.readZipEntry({filePath: 'wxfile://from/to.zip',entries: 'all'encoding: 'utf-8', // Specify the file's character encoding for reading. If no encoding is provided, the file's binary content will be read as an ArrayBuffersuccess(res) {console.log(res.entries)// res.entries === {// 'some_folder/my_file.txt': {// errMsg: 'readZipEntry:ok',// data: 'xxxxxx'// },// 'other_folder/orther_file.txt': {// errMsg: 'readZipEntry:ok',// data: 'xxxxxx'// }// }},fail(res) {console.log(res.errMsg)},})
This method is called using FileSystemManager.removeSavedFile(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | The path to the file that needs to be deleted. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail file not exist | The file cannot be found through the specified tempFilePath. |
This method is called using FileSystemManager.rename(Object object).
Property | Type | Default value | Required | Description |
oldPath | string | - | True | The source file path, which can be a regular file or directory, supporting local paths. |
newPath | string | - | True | The new file path, supporting local paths. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail permission denied, rename ${oldPath} -> ${newPath} | The specified source or target file does not have write permissions. |
fail no such file or directory, rename ${oldPath} -> ${newPath} | Source file does not exist, or the parent directory of the destination file path does not exist. |
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 APItry {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)}
This method is called using FileSystemManager.renameSync(string oldPath, string newPath).
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 APItry {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)}
This method is called using FileSystemManager.rmdir(Object object).
Property | Type | Default value | Required | Description |
dirPath | string | - | True | The path of the directory to be deleted. |
recursive | boolean | false | False | Whether to recursively delete the directory. If true, deletes the directory and all its subdirectories and files. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
errMsg | string | Error message. |
Value | 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 does not have write permissions. |
const fs = wx.getFileSystemManager()fs.rmdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,recursive: false,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.rmdirSync(`${wx.env.USER_DATA_PATH}/example`, false)console.log(res)} catch(e) {console.error(e)}
This method is called using FileSystemManager.rmdirSync(string dirPath, boolean recursive).
const fs = wx.getFileSystemManager()fs.rmdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,recursive: false,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.rmdirSync(`${wx.env.USER_DATA_PATH}/example`, false)console.log(res)} catch(e) {console.error(e)}
This method is called using FileSystemManager.saveFile(Object object).
Property | Type | Default value | Required | Description |
tempFilePath | string | - | True | The path of the temporary file. |
filePath | string | - | False | The path where the file will be saved. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
savedFilePath | number | The path of the saved file. |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail tempFilePath file not exist | The specified tempFilePath could not be found. |
fail permission denied, open "${filePath}" | No write permission for the specified filePath. |
fail no such file or directory "${dirPath}" | The parent directory does not exist. |
This method is called using number FileSystemManager.saveFileSync(string tempFilePath, string filePath).
This method is called using FileSystemManager.stat(Object object).
Property | Type | Default value | Required | Description |
path | string | - | True | The path of the file or directory. |
recursive | boolean | false | False | Whether to recursively get the Stats information of each file in the directory. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
stats | Stats/Object | When recursive is false, res.stats is a Stats object. When recursive is true and path is a directory, res.stats is an Object where the key is the relative path from the root path and the value is the corresponding Stats object. |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail permission denied, open ${path} | The specified path does not have read permissions. |
fail no such file or directory ${path} | The file does not exist. |
// Asynchronous versionlet fs = wx.getFileSystemManager()fs.stat({path: `${wx.env.USER_DATA_PATH}/testDir`,success: res => {console.log(res.stats.isDirectory())}})// Synchronous versionfs.statSync(`${wx.env.USER_DATA_PATH}/testDir`, false)
let fs = wx.getFileSystemManager()// Asynchronous versionfs.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())})}})// Synchronous versionfs.statSync(`${wx.env.USER_DATA_PATH}/testDir`, true)
This method is called using Stats|Object FileSystemManager.statSync(string path, boolean recursive).
// Asynchronous versionlet fs = wx.getFileSystemManager()fs.stat({path: `${wx.env.USER_DATA_PATH}/testDir`,success: res => {console.log(res.stats.isDirectory())}})// Synchronous versionfs.statSync(`${wx.env.USER_DATA_PATH}/testDir`, false)
let fs = wx.getFileSystemManager()// Asynchronous versionfs.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())})}})// Synchronous versionfs.statSync(`${wx.env.USER_DATA_PATH}/testDir`, true)
This method is called using FileSystemManager.truncate(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | Path to the file to be truncated (local path). |
length | number | 0 | False | The truncation position. Default value: 0. If the length is less than the file length (in bytes), only the first length bytes will be remained in the file, and the rest will be deleted. If the length is greater than the file length, the file will be expanded with empty bytes ('\\0'). |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
const fs = wx.getFileSystemManager()fs.truncate({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,length: 10, // Truncate from the 10th bytesuccess(res) {console.log(res)}})
This method is called using undefined FileSystemManager.truncateSync(Object object).
Property | Type | Default value | Required | Description |
filePath | string | | True | Path to the file to be truncated (local path). |
length | number | 0 | False | The truncation position. Default value: 0. If the length is less than the file length (in bytes), only the first length bytes will be remained in the file, and the rest will be deleted. If the length is greater than the file length, the file will be expanded with empty bytes ('\\0'). |
const fs = wx.getFileSystemManager()fs.truncateSync({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,length: 10, // Truncate from the 10th byte})
This method is called using FileSystemManager.unlink(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | Path to the file to be deleted. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail permission denied, open ${path} | The specified 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 provided filePath is a directory. |
const fs = wx.getFileSystemManager()fs.unlink({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.unlinkSync(`${wx.env.USER_DATA_PATH}/hello.txt`)console.log(res)} catch(e) {console.error(e)}
This method is called using FileSystemManager.unlinkSync(string filePath).
const fs = wx.getFileSystemManager()fs.unlink({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.unlinkSync(`${wx.env.USER_DATA_PATH}/hello.txt`)console.log(res)} catch(e) {console.error(e)}
This method is called using FileSystemManager.unzip(Object object).
Property | Type | Default value | Required | Description |
zipFilePath | string | - | True | Source file path, must be a zip file. |
targetPath | string | - | True | The path to the destination directory. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail permission denied, unzip ${zipFilePath} -> ${destPath} | No write permission for the destination file path. |
fail no such file or directory, unzip ${zipFilePath} -> ${destPath} | Source file does not exist, or the parent directory of the destination file path does not exist. |
const fs = wx.getFileSystemManager()fs.unzip({zipFilePath: `${wx.env.USER_DATA_PATH}/example.zip`,targetPath: '${wx.env.USER_DATA_PATH}/example',success(res) {console.log(res)},fail(res) {console.error(res)}})
This method is called using FileSystemManager.write(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True | |
data | string/ArrayBuffer | - | True | The text or binary data to be written. |
offset | number | 0 | False | Effective only when data is of type ArrayBuffer. Specifies the index in the ArrayBuffer to start writing from. Default is 0. |
length | number | - | False | Effective only when data is of type ArrayBuffer. Specifies the number of bytes to write. Default is the remaining bytes from offset. |
encoding. | string | utf8 | False | Character encoding for writing to the file. |
position | number | - | False | Specifies the offset from the beginning of the file where data should be written. If not provided or not a number, data will be written at the current pointer position. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Property | Type | Description |
bytesWritten | number | The actual number of bytes written to the file (note that the number of bytes written may not match the number of characters in the string). |
const fs = wx.getFileSystemManager()// Open a filefs.open({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+',success(res) {// Write to the filefs.write({fd: res.fd,data: 'some text',success(res) {console.log(res.bytesWritten)}})}})
This method is called using FileSystemManager.writeFile(Object object).
Property | Type | Default value | Required | Description |
fd | string | - | True | |
data | string/ArrayBuffer | - | True | The text or binary data to be written. |
offset | number | 0 | False | Effective only when data is of type ArrayBuffer. Specifies the index in the ArrayBuffer to start writing from. Default is 0. |
length | number | - | False | Effective only when data is of type ArrayBuffer. Specifies the number of bytes to write. Default is the remaining bytes from offset. |
encoding | string | utf8 | False | Character encoding for writing to the file. |
position | number | - | False | Specifies the offset from the beginning of the file where data should be written. If not provided or not a number, data will be written at the current pointer position. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Property | Type | Description |
bytesWritten | number | The actual number of bytes written to the file (note that the number of bytes written may not match the number of characters in the string). |
const fs = wx.getFileSystemManager()const fd = fs.openSync({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,flag: 'a+'})const res = fs.writeSync({fd: fd,data: 'some text'})console.log(res.bytesWritten)
This method is called using FileSystemManager.writeFile(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | The path to the file to be written. |
data | string/ArrayBuffer | - | True | The text or binary data to be written. |
encoding. | string | utf8 | False | Character encoding for writing to the file. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Property | Type | Description |
errMsg | string | Error message. |
Value | Description |
fail no such file or directory, open ${filePath} | The specified filePath directory does not exist. |
fail permission denied, open ${dirPath} | No write permission for the specified filePath. |
const fs = wx.getFileSystemManager()fs.writeFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,data: 'some text or arrayBuffer',encoding: 'utf8',success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.writeFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`,'some text or arrayBuffer','utf8')console.log(res)} catch(e) {console.error(e)}
This method is called using FileSystemManager.writeFileSync(string filePath, string|ArrayBuffer data, string encoding).
Value | Description |
ascii | - |
base64(When using base64 encoding, only pass the base64 content itself. Do not include the Data URI prefix, otherwise a fail base64 encode error will occur. For example, pass aGVsbG8= instead of data:image/png;base64,aGVsbG8= ) | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
const fs = wx.getFileSystemManager()fs.writeFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,data: 'some text or arrayBuffer',encoding: 'utf8',success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronous APItry {const res = fs.writeFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`,'some text or arrayBuffer','utf8')console.log(res)} catch(e) {console.error(e)}
Error code | Error message. | Description |
1300001 | operation not permitted | The operation is not allowed (e.g., it is expected to provide a file for filePath but actually a directory is provided). |
1300002 | no such file or directory ${path} | File/directory does not exist, or the parent directory is missing. |
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 specified path. |
1300020 | not a directory | The specified path is not a directory. |
1300021 | Is a directory | The specified path is a directory. |
1300022 | Invalid argument | Invalid argument, check if length or offset is out of range. |
1300036 | File name too long | The filename is too long. |
1300066 | directory not empty | The directory is not empty. |
1300201 | system error | The system API is failed to be called. |
1300202 | the maximum size of the file storage limit is exceeded | Storage space is insufficient, or file size exceeds the limit (100 MB). |
1300203 | base64 encode error | Character encoding conversion failed (e.g., incorrect base64 format). |
1300300 | sdcard not mounted | Failed to mount the Android SDCard. |
1300301 | unable to open as fileType | Unable to open the file as the specified fileType. |
1301000 | permission denied, cannot access file path | No access to the target path (e.g., usr directory) |
1301002 | data to write is empty | The data to be written is empty. |
1301003 | illegal operation on a directory | Illegal operation on a directory (e.g., specified filePath is an existing directory). |
1301004 | illegal operation on a package directory | Illegal operation on a 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 length value is out of range. |
1301007 | value of offset is out of range | The offset value is out of range. |
1301009 | value of position is out of range | The position value is out of range. |
1301100 | store directory is empty | The store directory is empty. |
1301102 | unzip open file fail | Failed to open the compressed file. |
1301103 | unzip entry fail | Failed to unzip a single file. |
1301104 | unzip fail | Unzipping 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 | The specified tempFilePath could not be found. |
1302001 | fail permission denied | No read/write permission for the specified fd path. |
1302002 | exceed max concurrent fd limit | Maximum number of file descriptors reached. |
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 is not provided. |
1302100 | array buffer is readonly | The arrayBuffer is read-only. |
This method is called using boolean Stats.isDirectory().
This method is called using boolean Stats.isFile().