# FileSystemManager.rename

重命名本地文件/目录

# 支持说明

应用能力 Android iOS PC 预览效果
小程序 3.12.0 3.11.0 3.10.0
扫码预览
用BoosHi扫码或PC端点击
网页应用 待开发 待开发 待开发 待补充

# 输入

继承标准对象输入,扩展属性描述:

名称 数据类型 必填 默认值 描述
oldPath string 源文件路径
newPath string 新文件路径

# 输出

继承标准对象输出,无扩展属性

# 代码示例

// 将所有保存的文件移除拓展标识
const fileSystemManager = bz.getFileSystemManager();

fileSystemManager.getSavedFileList({
  success(res) {
    res.fileList.forEach(removeExt);
  },
  fail(res) {
    console.log("获取失败", res.errMsg);
  },
});

function removeExt(fileItem) {
  console.log(`移除 ${fileItem.filePath} 的 ext`);
  const newPath = fileItem.filePath.replace(/(\..+)?$/, "");

  fileSystemManager.rename({
    oldPath: fileItem.filePath,
    newPath,
    success(_res) {
      console.log("重命名成功");
    },
    fail(res) {
      console.log("重命名失败", res.errMsg);
    },
  });
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
最后更新于 : 5/18/2023, 3:09:13 PM