文件

    FileSystemManager getFileSystemManager()

获取全局唯一的文件管理器

返回值

  • FileSystemManager

文件管理器

    FileSystemManager.access(Object object)

判断文件/目录是否存在

参数

  • Object object

    FileSystemManager.accessSync(string path)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.access 的同步版本,判断文件/目录是否存在

参数

  • string path

    要判断是否存在的文件/目录路径

错误

    FileSystemManager.appendFile(Object object)

支持版本: (core 版本 >= 1.1.0)

在文件结尾追加内容

参数

  • Object object

    FileSystemManager.appendFileSync(string filePath, string|ArrayBuffer data, string encoding)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.appendFile 的同步版本,在文件结尾追加内容

参数

  • string filePath

    要追加内容的文件路径

  • string|ArrayBuffer data

    要追加的文本或二进制数据

  • string encoding

    指定写入文件的字符编码,当前支持:

    • utf8

    • binary

错误

    FileSystemManager.copyFile(Object object)

复制文件

参数

  • Object object

    FileSystemManager.copyFileSync(string srcPath, string destPath)

FileSystemManager.copyFile 的同步版本,拷贝文件

参数

  • string srcPath

    源文件路径,只可以是普通文件

  • string destPath

    目标文件路径

错误

    FileSystemManager.getFileInfo(Object object)

获取本地临时文件或本地用户文件的文件信息

参数

  • Object object

  • success 回调函数

参数

  • Object res

    boolean Stats.isDirectory()

判断当前文件是否一个目录

返回值

  • boolean

表示当前文件是否一个目录

    boolean Stats.isFile()

判断当前文件是否一个普通文件

返回值

  • boolean

表示当前文件是否一个普通文件

    FileSystemManager.mkdir(Object object)

创建目录

参数

  • Object object

    FileSystemManager.mkdirSync(string dirPath, boolean recursive)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.mkdir 的同步版本,创建目录

参数

  • string dirPath

    创建的目录路径

  • boolean recursive

    是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。

错误

    FileSystemManager.readFile(Object object)

读取本地文件内容

参数

  • Object object

  • success 回调函数

参数

  • Object res

    FileSystemManager.readFileSync(string filePath, string encoding)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.readFile 的同步版本,读取文件

参数

  • string filePath

    要读取的文件的路径

  • string encoding

    指定写入文件的字符编码,当前支持:

    • utf8

    • binary(默认)

返回值

  • string|ArrayBuffer data

    文件内容

错误

    FileSystemManager.rename(Object object)

重命名文件,可以把文件从 oldPath 移动到 newPath

参数

  • Object object

    FileSystemManager.renameSync(string oldPath, string newPath)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.rename 的同步版本,重命名文件

参数

  • string oldPath

    源文件路径,可以是普通文件或目录

  • string newPath

    新文件路径

错误

    FileSystemManager.rmdir(Object object)

删除目录

参数

  • Object object

    FileSystemManager.rmdirSync(string dirPath, boolean recursive)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.rmdir 的同步版本,移除目录

参数

  • string dirPath

    要删除的目录路径

  • string newPath

    是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。

错误

    FileSystemManager.readdir(Object object)

读取目录内文件列表

参数

  • Object object

  • success 回调函数

参数

  • Object res

    FileSystemManager.readdirSync(string dirPath)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.readdir 的同步版本,读取目录

参数

  • string dirPath

    要删除的目录路径

返回值

  • Array files

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

错误

    Stats FileSystemManager.stat(Object object)

获取文件 Stats 对象

参数

  • Object object

  • success 回调函数

参数

  • Object res

    Stats|Array FileSystemManager.statSync(string path, boolean recursive)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.stat 的同步版本,获取 stat

参数

  • string path

    要删除的目录路径

  • boolean recursive

    是否递归获取目录中所有文件的信息

错误

    FileSystemManager.unlink(Object object)

删除文件

参数

  • Object object

    FileSystemManager.unlinkSync(string path)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.unlink 的同步版本,删除文件

参数

  • string filePath

    要删除的文件路径

错误

    FileSystemManager.unzip(Object object)

解压文件

参数

  • Object object

    FileSystemManager.writeFile(Object object)

写文件

参数

  • Object object

    FileSystemManager.writeFileSync(string filePath, string|ArrayBuffer data, string encoding)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.writeFile 的同步版本,写文件

参数

  • string filePath

    要追加内容的文件路径

  • string|ArrayBuffer data

    要追加的文本或二进制数据

  • string encoding

    指定写入文件的字符编码,当前支持:

    • utf8

    • binary

错误

    FileSystemManager.saveFile(Object object)

保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。

参数

  • Object object

  • success 回调函数

参数

  • Object res

    string FileSystemManager.saveFileSync(string tempFilePath, string filePath)

支持版本: (core 版本 >= 1.1.0)

FileSystemManager.saveFile 的同步版本,保存临时文件到本地。

参数

  • string tempFilePath

    临时存储文件路径

  • string filePath

    要存储的文件路径

返回值

  • string savedFilePath

    存储后的文件路径

错误

@Deprecated
FileSystemManager.removeSavedFile(Object object)

该接口已废弃,请使用 FileSystemManager.unlink 代替

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

参数

  • Object object

Last updated