uniapp 修改本地文件名称
背景
uniapp下载文件本地saveFile之后,文件名是时间戳的形式。而且uniapp官网并没有文件修改的方法
折腾了一天,终于解决了。
直接上代码
代码部分
使用plus.io的文件管理方法。(不得不吐槽一下,这个文档写的真的是云里雨雾)
/** * 修改文件名。 * @param {旧的文件路径} oldFilePath * @param {新的文件名} newFileName */ function RenameFile(oldFilePath,newFileName) { plus.io.resolveLocalFileSystemURL(oldFilePath, entry => { entry.getParent(_oldFile=>{ entry.moveTo(_oldFile,/+newFileName,newFilePath=>{ console.log(newFilePath,newFilePath.fullPath) }) }) }) }
Tips:这个方法改的名字要带后缀的,也可以改成Promise方法
和 uni.getSavedFileList搭配使用,可以直接调用uni.getSavedFileList返回的文件路径。