Article Directory
background
After uniapp downloads the local saveFile, the file name is in the form of a timestamp. And the uniapp official website does not have a method for file modification
After struggling for a day, it was finally resolved.
directly on the code
code part
Use plus.io's file management method. (I have to complain, this document is really written in the clouds and rain and fog)
/**
* 修改文件名。
* @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: The name of this method should be changed with a suffix, or it can be changed to a Promise method
Used in conjunction with uni.getSavedFileList, you can directly call the file path returned by uni.getSavedFileList.