title: FileSystemManager

sidebar_label: FileSystemManager

File Manager

Methods

readdirSync

The synchronous version of FileSystemManager.readdir.

Reference

  1. (dirPath: string) => string[]
Property Type Description
dirPath string Path to the directory to be read

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.readdirSync ✔️

access

Determines whether a file/directory exists.

Reference

  1. (option: AccessOption) => void
Property Type
option AccessOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.access ✔️

accessSync

The synchronous version of FileSystemManager.access.

Reference

  1. (path: string) => void
Property Type Description
path string Path to the file/directory of which you want to determine the existence

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.accessSync ✔️

appendFile

Appends content at the end of a file.

Reference

  1. (option: AppendFileOption) => void
Property Type
option AppendFileOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.appendFile ✔️

appendFileSync

The synchronous version of FileSystemManager.appendFile.

Reference

  1. (filePath: string, data: string | ArrayBuffer, encoding?: "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1") => void
Property Type Description
filePath string Path to the file to which you want to append content
data string | ArrayBuffer Text 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

API WeChat Mini-Program H5 React Native
FileSystemManager.appendFileSync ✔️

copyFile

Copies files.

Reference

  1. (option: CopyFileOption) => void
Property Type
option CopyFileOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.copyFile ✔️

copyFileSync

The synchronous version of FileSystemManager.copyFile.

Reference

  1. (srcPath: string, destPath: string) => void
Property Type Description
srcPath string The path to the source file, which can only be a normal file
destPath string The path to the target file

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.copyFileSync ✔️

getFileInfo

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

Reference

  1. (option: getFileInfoOption) => void
Property Type
option getFileInfoOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.getFileInfo ✔️

getSavedFileList

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

Reference

  1. (option?: getSavedFileListOption) => void
Property Type
option getSavedFileListOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.getSavedFileList ✔️

mkdir

Creates a directory.

Reference

  1. (option: MkdirOption) => void
Property Type
option MkdirOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.mkdir ✔️

mkdirSync

The synchronous version of FileSystemManager.mkdir.

Reference

  1. (dirPath: string, recursive?: boolean) => void
Property Type Description
dirPath string Path to the created directory
recursive boolean Indicates 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

API WeChat Mini-Program H5 React Native
FileSystemManager.mkdirSync ✔️

readFile

Reads local file content.

Reference

  1. (option: ReadFileOption) => void
Property Type
option ReadFileOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.readFile ✔️

readdir

Reads the list of files in the directory.

Reference

  1. (option: ReaddirOption) => void
Property Type
option ReaddirOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.readdir ✔️

removeSavedFile

Deletes the local cache files saved under the Mini Program.

Reference

  1. (option: RemoveSavedFileOption) => void
Property Type
option RemoveSavedFileOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.removeSavedFile ✔️

rename

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

Reference

  1. (option: RenameOption) => void
Property Type
option RenameOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.rename ✔️

renameSync

The synchronous version of FileSystemManager.rename.

Reference

  1. (oldPath: string, newPath: string) => void
Property Type Description
oldPath string The path to the source file, which can be a normal file or directory
newPath string New file path

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.renameSync ✔️

rmdir

Deletes a directory.

Reference

  1. (option: RmdirOption) => void
Property Type
option RmdirOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.rmdir ✔️

rmdirSync

The synchronous version of FileSystemManager.rmdir.

Reference

  1. (dirPath: string, recursive?: boolean) => void
Property Type Description
dirPath string The path to the directory to be deleted.
recursive boolean Indicates 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

API WeChat Mini-Program H5 React 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

  1. (option: SaveFileOption) => void
Property Type
option SaveFileOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.saveFile ✔️

stat

Gets the Stats object of the file.

Reference

  1. (option: StatOption) => void
Property Type
option StatOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.stat

unlink

Deletes files

Reference

  1. (option: UnlinkOption) => void
Property Type
option UnlinkOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.unlink ✔️

unlinkSync

The synchronous version of FileSystemManager.unlink.

Reference

  1. (filePath: string) => void
Property Type Description
filePath string Path to the file to be deleted

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.unlinkSync ✔️

unzip

Unzips files

Reference

  1. (option: UnzipOption) => void
Property Type
option UnzipOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.unzip ✔️

writeFile

Writes a file

Reference

  1. (option: WriteFileOption) => void
Property Type
option WriteFileOption

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.writeFile ✔️

writeFileSync

The synchronous version of FileSystemManager.writeFile.

Reference

  1. (filePath: string, data: string | ArrayBuffer, encoding?: "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1") => void
Property Type Description
filePath string Path to the file into which you want to write data
data string | ArrayBuffer Text 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

API WeChat Mini-Program H5 React Native
FileSystemManager.writeFileSync ✔️

statSync

The synchronous version of FileSystemManager.stat.

Reference

  1. (path: string, recursive?: boolean) => Stats | Record<string, any>
Property Type Description
path string The file/directory path.
recursive boolean Indicates whether to recursively get the Stats information of each file under the directory.

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.statSync ✔️

saveFileSync

The synchronous version of FileSystemManager.saveFile.

Reference

  1. (tempFilePath: string, filePath?: string) => number
Property Type Description
tempFilePath string Path to the temporarily stored files
filePath string Path to save the files

API Support

API WeChat Mini-Program H5 React Native
FileSystemManager.saveFileSync ✔️

readFileSync

The synchronous version of FileSystemManager.readFile.

Reference

  1. (filePath: string, encoding?: "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1") => string | ArrayBuffer
Property Type Description
filePath string The 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

API WeChat Mini-Program H5 React Native
FileSystemManager.readFileSync ✔️

Parameters

encoding

Valid values of encoding

Property Description
ascii
base64
binary
hex
ucs2 Read in little endian
ucs-2 Read in little endian
utf16le Read in little endian
utf-16le Read in little endian
utf-8
utf8
latin1

AccessOption

Property Type Required Description
path string Yes Path to the file/directory of which you want to determine the existence
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

AccessFailCallbackResult

Property Type Description
errMsg string Error message

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

AppendFileOption

Property Type Required Description
data string | ArrayBuffer Yes Text or binary data to be appended
filePath string Yes Path 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" No Specifies the character encoding of the written file
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

AppendFileFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Required Description
destPath string Yes The path to the target file
srcPath string Yes The path to the source file, which can only be a normal file
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

CopyFileFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Required Description
filePath string Yes Path to the files to be read
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

GetFileInfoFailCallbackResult

Property Type Description
errMsg string Error message

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

GetFileInfoSuccessCallbackResult

Property Type Description
size number File size in bytes
errMsg string Call result

getSavedFileListOption

Property Type Required Description
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

GetSavedFileListSuccessCallbackResult

Property Type Description
fileList GetSavedFileListSuccessCallbackResultFileItem[] File array
errMsg string Call result

GetSavedFileListSuccessCallbackResultFileItem

res.fileList is composed as follows

Property Type Description
createTime number The 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
filePath string Local path
size number Local file size in bytes

MkdirOption

Property Type Required Description
dirPath string Yes The path to the created directory
recursive boolean No Indicates 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) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

MkdirFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Required Description
filePath string Yes Path to the file to be read
encoding "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1" No Specifies 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) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

ReadFileFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Required Description
dirPath string Yes Path to the directory to be read
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

ReaddirFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Description
files string[] The array of file names in the specified directory.
errMsg string Call result

RemoveSavedFileOption

Property Type Required Description
filePath string Yes Path to the file to be deleted
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

RemoveSavedFileFailCallbackResult

Property Type Description
errMsg string Error message.

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

RenameOption

Property Type Required Description
newPath string Yes The new path to the file
oldPath string Yes The old path to the file, which can be a normal file or directory
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

RenameFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Required Description
dirPath string Yes The path to the directory to be deleted.
recursive boolean No Indicates 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) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

RmdirFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Required Description
tempFilePath string Yes Path to the temporarily stored files
filePath string No Path to save the files
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

SaveFileFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Description
savedFilePath number Path to the saved file
errMsg string Call result

StatOption

Property Type Required Description
path string Yes The file/directory path.
recursive boolean No Indicates whether to recursively get the Stats information of each file under the directory.
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

StatFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Description
stats Stats | Record<string, any> Stats
errMsg string Call result

UnlinkOption

Property Type Required Description
filePath string Yes Path to the file to be deleted
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

UnlinkFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Required Description
targetPath string Yes The path to the target directory
zipFilePath string Yes The path to the source file, which can only be a zip file
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

UnzipFailCallbackResult

Property Type Description
errMsg string Error 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

Property Type Required Description
data string | ArrayBuffer Yes Text or binary data to be written
filePath string Yes Path 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" No Specifies the character encoding of the written file
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

WriteFileFailCallbackResult

Property Type Description
errMsg string Error 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

API WeChat Mini-Program H5 React 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 ✔️