# Interface: FileSystemManager

FileSystemManager()

文件管理器

# Methods

# access

access(params: FileSystemManagerAccessParams): Promise‹FileSystemManagerAccessRes

判断文件/目录是否存在

# 参数:

属性 类型
params FileSystemManagerAccessParams

FileSystemManagerAccessParams

属性 类型 描述
path string 要判断是否存在的文件/目录路径 (本地路径)(仅支持微信,手Q)
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerAccessRes


# accessSync

accessSync(path: string): void

FileSystemManager.access 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
path string 要判断是否存在的文件/目录路径 (本地路径)

# 返回值:

void


# appendFile

appendFile(params: FileSystemManagerAppendFileParams): Promise‹FileSystemManagerAppendFileRes

在文件结尾追加内容

# 参数:

属性 类型
params FileSystemManagerAppendFileParams

FileSystemManagerAppendFileParams

属性 类型 描述
data string | ArrayBuffer 要追加的文本或二进制数据
encoding? Encoding 指定写入文件的字符编码
filePath string 要追加内容的文件路径 (本地路径)
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerAppendFileRes


# appendFileSync

appendFileSync(filePath: string, data: string | ArrayBuffer, encoding?: Encoding): void

FileSystemManager.appendFile 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
filePath string 要追加内容的文件路径 (本地路径)
data string | ArrayBuffer 要追加的文本或二进制数据
encoding? Encoding = 'utf8' - 指定写入文件的字符编码

# 返回值:

void


# copyFile

copyFile(params: FileSystemManagerCopyFileParams): Promise‹FileSystemManagerCopyFileRes

复制文件

# 参数:

属性 类型
params FileSystemManagerCopyFileParams

FileSystemManagerCopyFileParams

属性 类型 描述
destPath string 目标文件路径,支持本地路径
srcPath string 源文件路径,支持本地路径
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerCopyFileRes


# copyFileSync

copyFileSync(srcPath: string, destPath: string): void

FileSystemManager.copyFile 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
srcPath string 源文件路径,支持本地路径
destPath string 目标文件路径,支持本地路径

# 返回值:

void


# getFileInfo

getFileInfo(params: FileSystemManagerGetFileInfoParams): Promise‹FileSystemManagerGetFileInfoRes

获取该小程序下的 本地临时文件 或 本地缓存文件 信息(仅支持微信,手Q)

# 参数:

属性 类型
params FileSystemManagerGetFileInfoParams

FileSystemManagerGetFileInfoParams

属性 类型 描述
filePath string 要读取的文件路径 (本地路径)
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerGetFileInfoRes


# getSavedFileList

getSavedFileList(params?: FileSystemManagerGetSavedFileListParams): Promise‹FileSystemManagerGetSavedFileListRes

获取该小程序下已保存的本地缓存文件列表

# 参数:

属性 类型
params? FileSystemManagerGetSavedFileListParams

FileSystemManagerGetSavedFileListParams

属性 类型 描述
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerGetSavedFileListRes

getSavedFileList(params?: FileSystemManagerGetSavedFileListParams): Promise‹FileSystemManagerGetSavedFileListRes

删除该小程序下已保存的本地缓存文件

# 参数:

属性 类型
params? FileSystemManagerGetSavedFileListParams

FileSystemManagerGetSavedFileListParams

属性 类型 描述
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerGetSavedFileListRes


# importFile

importFile(params: FileSystemManagerImportFileParams): Promise‹FileSystemManagerImportFileRes

import文件到游戏沙箱目录,调用此接口会打开文件选择器,仅能选择指定目录里的文件(此目录的文件是从其他app如微信、手Q分享到有乐的)

# 参数:

属性 类型
params FileSystemManagerImportFileParams

FileSystemManagerImportFileParams

属性 类型 描述
filePath string 文件路径
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerImportFileRes


# mkdir

mkdir(params: FileSystemManagerMkdirParams): Promise‹FileSystemManagerMkdirRes

创建目录

# 参数:

属性 类型
params FileSystemManagerMkdirParams

FileSystemManagerMkdirParams

属性 类型 描述
dirPath string 创建的目录路径 (本地路径)
recursive? boolean 是否在递归创建该目录的上级目录后再创建该目录。
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerMkdirRes


# mkdirSync

mkdirSync(dirPath: string, recursive?: boolean): void

FileSystemManager.mkdir 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
dirPath string 创建的目录路径 (本地路径)
recursive? boolean 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。

# 返回值:

void


# readFile

readFile(params: FileSystemManagerReadFileParams): Promise‹FileSystemManagerReadFileRes

读取本地文件内容

# 参数:

属性 类型
params FileSystemManagerReadFileParams

FileSystemManagerReadFileParams

属性 类型 描述
encoding? Encoding 指定读取文件的字符编码,如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容
filePath string 要读取的文件的路径 (本地路径)
length? string 指定文件的长度,如果不指定,则读到文件末尾。
position? string 从文件指定位置开始读,如果不指定,则从文件头开始读。
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerReadFileRes


# readFileSync

readFileSync(filePath: string, encoding?: Encoding, position?: string, length?: string): string | ArrayBuffer

FileSystemManager.readFile 的同步版本(仅支持微信,手Q)

todo wx 文档似乎有误,这里 position/length 的类型看描述,应为 number

# 参数:

属性 类型 描述
filePath string 要读取的文件的路径 (本地路径)
encoding? Encoding 指定读取文件的字符编码,如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容
position? string 从文件指定位置开始读,如果不指定,则从文件头开始读。 读取的范围应该是左闭右开区间 [position, position+length)。 有效范围:[0, fileLength - 1]。 单位:byte
length? string 指定文件的长度,如果不指定,则读到文件末尾。 有效范围:[1, fileLength]。 单位:byte

# 返回值:

string | ArrayBuffer

文件内容


# readdir

readdir(params: FileSystemManagerReaddirParams): Promise‹FileSystemManagerReaddirRes

读取目录内文件列表

# 参数:

属性 类型
params FileSystemManagerReaddirParams

FileSystemManagerReaddirParams

属性 类型 描述
dirPath string 要读取的目录路径 (本地路径)
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerReaddirRes


# readdirSync

readdirSync(dirPath: string): string[]

FileSystemManager.readdir 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
dirPath string 要读取的目录路径 (本地路径)

# 返回值:

string[]

指定目录下的文件名数组。


# removeSavedFile

removeSavedFile(params: FileSystemManagerRemoveSavedFileParams): Promise‹FileSystemManagerRemoveSavedFileRes

删除该小程序下已保存的本地缓存文件(仅支持微信,手Q)

# 参数:

属性 类型
params FileSystemManagerRemoveSavedFileParams

FileSystemManagerRemoveSavedFileParams

属性 类型 描述
filePath string 需要删除的文件路径 (本地路径)
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerRemoveSavedFileRes


# removeSavedFileSync

removeSavedFileSync(filePath: string): void

FileSystemManager.removeSavedFile 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
filePath string 需要删除的文件路径 (本地路径)

# 返回值:

void


# rename

rename(params: FileSystemManagerRenameParams): Promise‹FileSystemManagerRenameRes

重命名文件

description 可以把文件从 oldPath 移动到 newPath

# 参数:

属性 类型
params FileSystemManagerRenameParams

FileSystemManagerRenameParams

属性 类型 描述
newPath string 新文件路径,支持本地路径
oldPath string 源文件路径,支持本地路径
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerRenameRes


# renameSync

renameSync(oldPath: string, newPath: string): void

FileSystemManager.rename 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
oldPath string 源文件路径,支持本地路径
newPath string 新文件路径,支持本地路径

# 返回值:

void


# rmdir

rmdir(params: FileSystemManagerRmdirParams): Promise‹FileSystemManagerRmdirRes

删除目录

# 参数:

属性 类型
params FileSystemManagerRmdirParams

FileSystemManagerRmdirParams

属性 类型 描述
dirPath string 要删除的目录路径 (本地路径)
recursive? boolean 是否递归删除目录。
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerRmdirRes


# rmdirSync

rmdirSync(dirPath: string, recursive?: boolean): void

FileSystemManager.rmdir 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
dirPath string 要删除的目录路径 (本地路径)
recursive? boolean = false - 是否递归删除目录。 如果为 true,则删除该目录和该目录下的所有子目录以及文件。

# 返回值:

void


# saveFile

saveFile(params: FileSystemManagerSaveFileParams): Promise‹FileSystemManagerSaveFileRes

保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用(仅支持微信,手Q)

# 参数:

属性 类型
params FileSystemManagerSaveFileParams

FileSystemManagerSaveFileParams

属性 类型 描述
filePath? string 要存储的文件路径 (本地路径)
tempFilePath string 临时存储文件路径 (本地路径)
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerSaveFileRes


# saveFileSync

saveFileSync(tempFilePath: string, filePath?: string): string

FileSystemManager.saveFile 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
tempFilePath string 临时存储文件路径 (本地路径)
filePath? string 要存储的文件路径 (本地路径)

# 返回值:

string

存储后的文件路径 (本地路径)


# shareFile

shareFile(params: FileSystemManagerShareFileParams): Promise‹FileSystemManagerShareFileRes

分享文件到其他平台,例如微信、手Q等,调用此接口会调用操作系统的文件分享(仅支持有乐)

# 参数:

属性 类型
params FileSystemManagerShareFileParams

FileSystemManagerShareFileParams

属性 类型 描述
filePath string 文件路径
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerShareFileRes


# stat

stat(params: FileSystemManagerStatParams): Promise‹FileSystemManagerStatRes

获取文件 Stats 对象

# 参数:

属性 类型
params FileSystemManagerStatParams

FileSystemManagerStatParams

属性 类型 描述
path string 文件/目录路径 (本地路径)
recursive? boolean 是否递归获取目录下的每个文件的 Stats 信息
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerStatRes


# statSync

statSync(path: string, recursive?: boolean): Stats | Record‹string, Stats

FileSystemManager.stat 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
path string 文件/目录路径 (本地路径)
recursive? boolean = false - 是否递归获取目录下的每个文件的 Stats 信息

# 返回值:

Stats | Record‹string, Stats

当 recursive 为 false 时,res.stats 是一个 Stats 对象。 当 recursive 为 true 且 path 是一个目录的路径时,res.stats 是一个 Object,key 以 path 为根路径的相对路径,value 是该路径对应的 Stats 对象。


unlink(params: FileSystemManagerUnlinkParams): Promise‹FileSystemManagerUnlinkRes

删除文件(仅支持微信,手Q)

# 参数:

属性 类型
params FileSystemManagerUnlinkParams

FileSystemManagerUnlinkParams

属性 类型 描述
filePath string 要删除的文件路径 (本地路径)
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerUnlinkRes


# unlinkSync

unlinkSync(filePath: string): void

FileSystemManager.unlink 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
filePath string 要删除的文件路径 (本地路径)

# 返回值:

void


# unzip

unzip(params: FileSystemManagerUnzipParams): Promise‹FileSystemManagerUnzipRes

解压文件(仅支持微信,手Q)

# 参数:

属性 类型
params FileSystemManagerUnzipParams

FileSystemManagerUnzipParams

属性 类型 描述
targetPath string 目标目录路径, 支持本地路径
zipFilePath string 源文件路径,支持本地路径, 只可以是 zip 压缩文件
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerUnzipRes


# writeFile

writeFile(params: FileSystemManagerWriteFileParams): Promise‹FileSystemManagerWriteFileRes

写文件

# 参数:

属性 类型
params FileSystemManagerWriteFileParams

FileSystemManagerWriteFileParams

属性 类型 描述
data string | ArrayBuffer 要写入的文本或二进制数据
encoding? Encoding 指定写入文件的字符编码
filePath string 要写入的文件路径 (本地路径)
complete? Method 接口调用结束的回调函数(调用成功、失败都会执行)
fail? Method 接口调用失败的回调函数
success? Method 接口调用成功的回调函数

# 返回值:

Promise‹FileSystemManagerWriteFileRes


# writeFileSync

writeFileSync(filePath: string, data: string | ArrayBuffer, encoding?: Encoding): void

FileSystemManager.writeFile 的同步版本(仅支持微信,手Q)

# 参数:

属性 类型 描述
filePath string 要写入的文件路径 (本地路径)
data string | ArrayBuffer 要写入的文本或二进制数据
encoding? Encoding = 'utf8' - 指定写入文件的字符编码

# 返回值:

void