更新记录

1.0.1(2026-07-01)

新增

  • getFileInfo:获取文件信息,返回文件名称、大小、MIME 类型、创建时间、修改时间
  • Android 平台支持 content:// 协议和普通文件路径

1.0.0(2026-07-01)

新增

  • 初始版本发布
  • 支持 Android、iOS 平台
  • access:判断文件/目录是否存在
  • copyFile:复制文件(支持 content:// 协议)
  • mkdir:创建目录(支持递归创建)
  • readFile:读取文件内容(支持 base64 / utf-8 / ascii 编码,不传则返回 ArrayBuffer)
  • remove:递归删除目录或单个文件
  • readdir:读取目录内文件列表
  • rename:重命名文件/目录(支持移动)
  • getSandboxPath / getCachePath / getUserDataPath:获取应用目录路径

平台兼容性

uni-app(5.07)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android Android插件版本 iOS iOS插件版本 鸿蒙
- - - - - - 5.0 1.0.1 14 1.0.1 -
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - - -

uni-app x(5.07)

Chrome Safari Android iOS 鸿蒙 微信小程序
- - - - - -

cc-fs

文件系统操作 UTS API 插件,支持 Android、iOS。

功能特性

  • ✅ access:判断文件/目录是否存在
  • ✅ copyFile:复制文件(支持 content:// 协议)
  • ✅ mkdir:创建目录(支持递归创建)
  • ✅ readFile:读取文件内容(支持 base64 / utf-8 / ascii 编码,不传则返回 ArrayBuffer)
  • ✅ remove:递归删除目录或单个文件
  • ✅ readdir:读取目录内文件列表
  • ✅ rename:重命名文件/目录(支持移动)

使用方法

import { access, copyFile, mkdir, readFile, remove, readdir, rename, getSandboxPath, getCachePath, getUserDataPath } from "@/uni_modules/cc-fs";

目录获取方法

方法名 返回值 说明 Android 路径 iOS 路径
getSandboxPath() string 应用沙箱根目录 /data/data/<package> NSHomeDirectory()/Documents
getCachePath() string 应用缓存目录 /data/data/<package>/cache Library/Caches
getUserDataPath() string 应用数据目录 /data/data/<package>/files Documents

access

判断文件或目录是否存在。

access({
  path: "/path/to/file.txt",
  success(res) {
    console.log(res.exists); // true / false
  }
});

参数

参数名 类型 必填 说明
path string 需要判断的文件/目录路径
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数

success 回调参数

属性 类型 说明
exists boolean 文件/目录是否存在
errMsg string 固定值 "access:ok"

copyFile

复制文件(支持 content:// 协议)。

copyFile({
  srcPath: "/path/to/source.txt",
  destPath: "/path/to/dest.txt",
  success(res) {
    console.log("复制成功");
  }
});

参数

参数名 类型 必填 说明
srcPath string 源文件路径
destPath string 目标文件路径
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数

success 回调参数

属性 类型 说明
errMsg string 固定值 "copyFile:ok"

mkdir

创建目录。

mkdir({
  path: "/path/to/new/dir",
  recursive: true, // 是否递归创建,默认 false
  success(res) {
    console.log("创建成功");
  }
});

参数

参数名 类型 必填 默认值 说明
path string - 需要创建的目录路径
recursive boolean false 是否递归创建父目录
success Function - 接口调用成功的回调函数
fail Function - 接口调用失败的回调函数
complete Function - 接口调用结束的回调函数

success 回调参数

属性 类型 说明
errMsg string 固定值 "mkdir:ok"

readFile

读取本地文件内容。

// 以 utf-8 编码读取文本文件
readFile({
  path: "/path/to/file.txt",
  encoding: "utf-8",
  success(res) {
    console.log(res.data); // string
  }
});

// 以 ArrayBuffer 格式读取二进制文件
readFile({
  path: "/path/to/file.bin",
  success(res) {
    console.log(res.data); // ArrayBuffer
  }
});

参数

参数名 类型 必填 默认值 说明
path string - 文件路径
encoding string - 字符编码,可选 base64 / utf-8 / ascii,不传则返回 ArrayBuffer
success Function - 接口调用成功的回调函数
fail Function - 接口调用失败的回调函数
complete Function - 接口调用结束的回调函数

success 回调参数

属性 类型 说明
data string | ArrayBuffer 文件内容,指定 encoding 时返回 string,否则返回 ArrayBuffer
errMsg string 固定值 "readFile:ok"

remove

递归删除目录或单个文件。

remove({
  path: "/path/to/file-or-dir",
  success(res) {
    console.log("删除成功");
  }
});

参数

参数名 类型 必填 说明
path string 需要删除的文件或目录路径
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数

success 回调参数

属性 类型 说明
errMsg string 固定值 "remove:ok"

readdir

读取目录内文件列表。

readdir({
  path: "/path/to/dir",
  success(res) {
    console.log(res.files); // ReaddirItem[]
    res.files.forEach(item => {
      console.log(item.name, item.isDirectory, item.size);
    });
  }
});

参数

参数名 类型 必填 说明
path string 目录路径
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数

success 回调参数

属性 类型 说明
files ReaddirItem[] 目录内文件列表
errMsg string 固定值 "readdir:ok"

ReaddirItem

属性 类型 说明
name string 文件/目录名称
path string 文件/目录路径
isDirectory boolean 是否为目录
size number 文件大小,单位字节
modifyTime number 最后修改时间,时间戳(毫秒)

rename

重命名文件/目录,可将文件从 oldPath 移动到 newPath。

rename({
  oldPath: "/path/to/old.txt",
  newPath: "/path/to/new.txt",
  success(res) {
    console.log("重命名成功");
  }
});

参数

参数名 类型 必填 说明
oldPath string 源文件/目录路径
newPath string 目标文件/目录路径
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数

success 回调参数

属性 类型 说明
errMsg string 固定值 "rename:ok"

错误码

错误码 说明
9010001 文件/目录不存在
9010002 创建目录失败
9010003 复制文件失败
9010004 路径参数为空
9010005 源文件不存在
9010006 读取文件失败
9010007 删除失败
9010008 读取目录失败
9010009 重命名失败

隐私、权限声明

1. 本插件需要申请的系统权限列表:

文件读写(仅限用户主动指定的文件路径)

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。