Skip to main content
Version: Next

FileSystemManager

File Manager

Methods

readdirSync

The synchronous version of FileSystemManager.readdir.

Reference

(dirPath: string) => string[]
PropertyTypeDescription
dirPathstringPath to the directory to be read

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.readdirSync✔️

access

Determines whether a file/directory exists.

Reference

(option: AccessOption) => void
PropertyType
optionAccessOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.access✔️

accessSync

The synchronous version of FileSystemManager.access.

Reference

(path: string) => void
PropertyTypeDescription
pathstringPath to the file/directory of which you want to determine the existence

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.accessSync✔️

appendFile

Appends content at the end of a file.

Reference

(option: AppendFileOption) => void
PropertyType
optionAppendFileOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.appendFile✔️

appendFileSync

The synchronous version of FileSystemManager.appendFile.

Reference

(filePath: string, data: string | ArrayBuffer, encoding?: "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1") => void
PropertyTypeDescription
filePathstringPath to the file to which you want to append content
datastring | ArrayBufferText or binary data to be appended
encoding"ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1"Specifies the character encoding of the written file

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.appendFileSync✔️

copyFile

Copies files.

Reference

(option: CopyFileOption) => void
PropertyType
optionCopyFileOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.copyFile✔️

copyFileSync

The synchronous version of FileSystemManager.copyFile.

Reference

(srcPath: string, destPath: string) => void
PropertyTypeDescription
srcPathstringThe path to the source file, which can only be a normal file
destPathstringThe path to the target file

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.copyFileSync✔️

getFileInfo

Gets the information of local temporary files or local cache files under the Mini Program.

Reference

(option: getFileInfoOption) => void
PropertyType
optiongetFileInfoOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.getFileInfo✔️

getSavedFileList

Gets the list of local cache files saved under the Mini Program.

Reference

(option?: getSavedFileListOption) => void
PropertyType
optiongetSavedFileListOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.getSavedFileList✔️

mkdir

Creates a directory.

Reference

(option: MkdirOption) => void
PropertyType
optionMkdirOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.mkdir✔️

mkdirSync

The synchronous version of FileSystemManager.mkdir.

Reference

(dirPath: string, recursive?: boolean) => void
PropertyTypeDescription
dirPathstringPath to the created directory
recursivebooleanIndicates whether to create the directory after recursively creating the upper-layer directory. If the upper-layer directory already exists, do not create it. If dirPath is a/b/c/d and "recursive" is true, directory a will be created, and then directory b will be created under directory a, and so on, until directory d under directory a/b/c is created.

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.mkdirSync✔️

readFile

Reads local file content.

Reference

(option: ReadFileOption) => void
PropertyType
optionReadFileOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.readFile✔️

readdir

Reads the list of files in the directory.

Reference

(option: ReaddirOption) => void
PropertyType
optionReaddirOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.readdir✔️

removeSavedFile

Deletes the local cache files saved under the Mini Program.

Reference

(option: RemoveSavedFileOption) => void
PropertyType
optionRemoveSavedFileOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.removeSavedFile✔️

rename

Renames a file, and moves it from oldPath to newPath.

Reference

(option: RenameOption) => void
PropertyType
optionRenameOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.rename✔️

renameSync

The synchronous version of FileSystemManager.rename.

Reference

(oldPath: string, newPath: string) => void
PropertyTypeDescription
oldPathstringThe path to the source file, which can be a normal file or directory
newPathstringNew file path

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.renameSync✔️

rmdir

Deletes a directory.

Reference

(option: RmdirOption) => void
PropertyType
optionRmdirOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.rmdir✔️

rmdirSync

The synchronous version of FileSystemManager.rmdir.

Reference

(dirPath: string, recursive?: boolean) => void
PropertyTypeDescription
dirPathstringThe path to the directory to be deleted.
recursivebooleanIndicates whether to recursively delete the directory. If the value is true, the directory and all subdirectories and files under the directory are deleted.

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.rmdirSync✔️

saveFile

Saves temporary files to the local device. This API moves temporary files, so tempFilePath will not be available after the API is successfully called.

Reference

(option: SaveFileOption) => void
PropertyType
optionSaveFileOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.saveFile✔️

stat

Gets the Stats object of the file.

Reference

(option: StatOption) => void
PropertyType
optionStatOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.stat

Deletes files

Reference

(option: UnlinkOption) => void
PropertyType
optionUnlinkOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.unlink✔️

unlinkSync

The synchronous version of FileSystemManager.unlink.

Reference

(filePath: string) => void
PropertyTypeDescription
filePathstringPath to the file to be deleted

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.unlinkSync✔️

unzip

Unzips files

Reference

(option: UnzipOption) => void
PropertyType
optionUnzipOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.unzip✔️

writeFile

Writes a file

Reference

(option: WriteFileOption) => void
PropertyType
optionWriteFileOption

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.writeFile✔️

writeFileSync

The synchronous version of FileSystemManager.writeFile.

Reference

(filePath: string, data: string | ArrayBuffer, encoding?: "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1") => void
PropertyTypeDescription
filePathstringPath to the file into which you want to write data
datastring | ArrayBufferText or binary data to be written
encoding"ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1"Specifies the character encoding of the written file

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.writeFileSync✔️

statSync

The synchronous version of FileSystemManager.stat.

Reference

(path: string, recursive?: boolean) => Stats | Record<string, any>
PropertyTypeDescription
pathstringThe file/directory path.
recursivebooleanIndicates whether to recursively get the Stats information of each file under the directory.

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.statSync✔️

saveFileSync

The synchronous version of FileSystemManager.saveFile.

Reference

(tempFilePath: string, filePath?: string) => number
PropertyTypeDescription
tempFilePathstringPath to the temporarily stored files
filePathstringPath to save the files

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.saveFileSync✔️

readFileSync

The synchronous version of FileSystemManager.readFile.

Reference

(filePath: string, encoding?: "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1") => string | ArrayBuffer
PropertyTypeDescription
filePathstringThe path to the file to be read.
encoding"ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1"Specifies the character encoding of the read file. If encoding is not specified, the binary content of the file is read in ArrayBuffer format.

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.readFileSync✔️

Parameters

encoding

Valid values of encoding

PropertyDescription
ascii
base64
binary
hex
ucs2Read in little endian
ucs-2Read in little endian
utf16leRead in little endian
utf-16leRead in little endian
utf-8
utf8
latin1

AccessOption

PropertyTypeRequiredDescription
pathstringYesPath to the file/directory of which you want to determine the existence
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

AccessFailCallbackResult

PropertyTypeDescription
errMsgstringError message

Valid values:
- 'fail no such file or directory path': File/directory does not exist;

AppendFileOption

PropertyTypeRequiredDescription
datastring | ArrayBufferYesText or binary data to be appended
filePathstringYesPath to the file to which you want to append content
encoding"ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1"NoSpecifies the character encoding of the written file
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

AppendFileFailCallbackResult

PropertyTypeDescription
errMsgstringError message

Valid values:
- 'fail no such file or directory, open filePath': File with the specified filePath does not exist;
- 'fail illegal operation on a directory, open "filePath"': The specified filePath is an existing directory;
- 'fail permission denied, open dirPath': No write permission on the specified filePath;
- 'fail sdcard not mounted': The SD card is not mounted;

CopyFileOption

PropertyTypeRequiredDescription
destPathstringYesThe path to the target file
srcPathstringYesThe path to the source file, which can only be a normal file
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

CopyFileFailCallbackResult

PropertyTypeDescription
errMsgstringError message

Valid values:
- 'fail permission denied, copyFile srcPath -> destPath': No write permission on the specified target file path;
- 'fail no such file or directory, copyFile srcPath ->destPath': The source file does not exist, or the upper-layer directory of the target file path does not exist;
- 'fail the maximum size of the file storage limit is exceeded': Insufficient storage space;

getFileInfoOption

PropertyTypeRequiredDescription
filePathstringYesPath to the files to be read
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

GetFileInfoFailCallbackResult

PropertyTypeDescription
errMsgstringError message

Valid values:
- 'fail file not exist': No file found with the specified filePath;

GetFileInfoSuccessCallbackResult

PropertyTypeDescription
sizenumberFile size in bytes
errMsgstringCall result

getSavedFileListOption

PropertyTypeRequiredDescription
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

GetSavedFileListSuccessCallbackResult

PropertyTypeDescription
fileListGetSavedFileListSuccessCallbackResultFileItem[]File array
errMsgstringCall result

GetSavedFileListSuccessCallbackResultFileItem

res.fileList is composed as follows

PropertyTypeDescription
createTimenumberThe timestamp when the file was saved, which is defined as the number of seconds that have elapsed since 1970/01/01 08:00:00 to the current time
filePathstringLocal path
sizenumberLocal file size in bytes

MkdirOption

PropertyTypeRequiredDescription
dirPathstringYesThe path to the created directory
recursivebooleanNoIndicates whether to create the directory after recursively creating the upper-layer directory. If the upper-layer directory already exists, do not create it. If dirPath is a/b/c/d and "recursive" is true, directory a will be created, and then directory b will be created under directory a, and so on, until directory d under directory a/b/c is created.
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

MkdirFailCallbackResult

PropertyTypeDescription
errMsgstringError message

Valid value:
- 'fail no such file or directory dirPath': The upper-layer directory does not exist;
- 'fail permission denied, open dirPath': No write permission on the specified filePath;
- 'fail file already exists dirPath': A file or directory with the same name already exists;

ReadFileOption

PropertyTypeRequiredDescription
filePathstringYesPath to the file to be read
encoding"ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1"NoSpecifies the character encoding of the read file. If encoding is not specified, the binary content of the file is read in ArrayBuffer format.
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

ReadFileFailCallbackResult

PropertyTypeDescription
errMsgstringError message.

Valid value:
- 'fail no such file or directory, open filePath': The directory where the specified filePath is located does not exist;
- 'fail permission denied, open dirPath': No read permission on the specified filePath;

ReaddirOption

PropertyTypeRequiredDescription
dirPathstringYesPath to the directory to be read
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

ReaddirFailCallbackResult

PropertyTypeDescription
errMsgstringError message.

Valid values:
- 'fail no such file or directory dirPath': Directory does not exist;
- 'fail not a directory dirPath': dirPath is not a directory;
- 'fail permission denied, open dirPath': No read permission on the specified filePath;

ReaddirSuccessCallbackResult

PropertyTypeDescription
filesstring[]The array of file names in the specified directory.
errMsgstringCall result

RemoveSavedFileOption

PropertyTypeRequiredDescription
filePathstringYesPath to the file to be deleted
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

RemoveSavedFileFailCallbackResult

PropertyTypeDescription
errMsgstringError message.

Valid values:
- 'fail file not exist': No file found with the specified tempFilePath;

RenameOption

PropertyTypeRequiredDescription
newPathstringYesThe new path to the file
oldPathstringYesThe old path to the file, which can be a normal file or directory
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

RenameFailCallbackResult

PropertyTypeDescription
errMsgstringError message.

Valid values:
- 'fail permission denied, rename oldPath -> newPath': No write permission on the specified source file or target file;
- 'fail no such file or directory, rename oldPath -> newPath': The source file does not exist, or the upper-layer directory of the target file path does not exist;

RmdirOption

PropertyTypeRequiredDescription
dirPathstringYesThe path to the directory to be deleted.
recursivebooleanNoIndicates whether to recursively delete the directory. If the value is true, the directory and all subdirectories and files under the directory are deleted.
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

RmdirFailCallbackResult

PropertyTypeDescription
errMsgstringError message.

Valid values:
- 'fail no such file or directory dirPath': Directory does not exist;
- 'fail directory not empty': Directory is not empty;
- 'fail permission denied, open dirPath': No write permission on the specified dirPath;

SaveFileOption

PropertyTypeRequiredDescription
tempFilePathstringYesPath to the temporarily stored files
filePathstringNoPath to save the files
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

SaveFileFailCallbackResult

PropertyTypeDescription
errMsgstringError message

Valid values:
- 'fail tempFilePath file not exist': No file found with the specified tempFilePath;
- 'fail permission denied, open "filePath"': No write permission on the specified filePath;
- 'fail no such file or directory "dirPath"': The upper-layer directory does not exist;
- 'fail the maximum size of the file storage limit is exceeded': Insufficient storage space;

SaveFileSuccessCallbackResult

PropertyTypeDescription
savedFilePathnumberPath to the saved file
errMsgstringCall result

StatOption

PropertyTypeRequiredDescription
pathstringYesThe file/directory path.
recursivebooleanNoIndicates whether to recursively get the Stats information of each file under the directory.
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

StatFailCallbackResult

PropertyTypeDescription
errMsgstringError message.

Valid values:
- 'fail permission denied, open path': No read permission on the specified path;
- 'fail no such file or directory path': File does not exist;

StatSuccessCallbackResult

PropertyTypeDescription
statsStats | Record<string, any>Stats
errMsgstringCall result

UnlinkOption

PropertyTypeRequiredDescription
filePathstringYesPath to the file to be deleted
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

UnlinkFailCallbackResult

PropertyTypeDescription
errMsgstringError message.

Valid values:
- 'fail permission denied, open path': No read permission on the specified path;
- 'fail no such file or directory path': File does not exist;
- 'fail operation not permitted, unlink filePath': The passed filePath is a directory;

UnzipOption

PropertyTypeRequiredDescription
targetPathstringYesThe path to the target directory
zipFilePathstringYesThe path to the source file, which can only be a zip file
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

UnzipFailCallbackResult

PropertyTypeDescription
errMsgstringError message.

Valid values:
- 'fail permission denied, unzip zipFilePath -> destPath': No write permission on the specified target file path;
- 'fail no such file or directory, unzip zipFilePath -> "destPath': The source file does not exist, or the upper-layer directory of the target file path does not exist;

WriteFileOption

PropertyTypeRequiredDescription
datastring | ArrayBufferYesText or binary data to be written
filePathstringYesPath to the file into which you want to write data
encoding"ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1"NoSpecifies the character encoding of the written file
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

WriteFileFailCallbackResult

PropertyTypeDescription
errMsgstringError message.

Valid valus:
- 'fail no such file or directory, open filePath': The directory where the specified filePath is located does not exist;
- 'fail permission denied, open dirPath': No write permission on the specified filePath;
- 'fail the maximum size of the file storage limit is exceeded': Insufficient storage space;

API Support

APIWeChat Mini-ProgramH5React Native
FileSystemManager.readdirSync✔️
FileSystemManager.access✔️
FileSystemManager.accessSync✔️
FileSystemManager.appendFile✔️
FileSystemManager.appendFileSync✔️
FileSystemManager.copyFile✔️
FileSystemManager.copyFileSync✔️
FileSystemManager.getFileInfo✔️
FileSystemManager.getSavedFileList✔️
FileSystemManager.mkdir✔️
FileSystemManager.mkdirSync✔️
FileSystemManager.readFile✔️
FileSystemManager.readdir✔️
FileSystemManager.removeSavedFile✔️
FileSystemManager.rename✔️
FileSystemManager.renameSync✔️
FileSystemManager.rmdir✔️
FileSystemManager.rmdirSync✔️
FileSystemManager.saveFile✔️
FileSystemManager.stat
FileSystemManager.unlink✔️
FileSystemManager.unlinkSync✔️
FileSystemManager.unzip✔️
FileSystemManager.writeFile✔️
FileSystemManager.writeFileSync✔️
FileSystemManager.statSync✔️
FileSystemManager.saveFileSync✔️
FileSystemManager.readFileSync✔️