xx.writeFile wx.getSavedFileList 空
发布于 5 年前 作者 juan60 2816 次浏览 来自 问答

const mytmp = `${wx.env.USER_DATA_PATH}/${fileName}`

xx.writeFile({

filePath: mytmp,

encoding: ‘binary’,

data: fffff,

success: res => {

console.log(‘write file ok-----------’, fileName)

callback({

path: mytmp,

result: res

})

现在是缓存超过10M 无法清空, 如果我每次都用一个文件名,有的安卓系统不能覆盖已有文件。 求解

2 回复

请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

无语十分钟。。。。。

答案:

let xx2 = wx.getFileSystemManager()

const basepath = `${wx.env.USER_DATA_PATH}`

xx2.readdir({

dirPath: basepath,/// 获取文件列表

success(res) {

console.log(res)

res.files.forEach((val) => { // 遍历文件列表里的数据

console.log(val)

xx2.unlink({

filePath: basepath + ‘/’ +val

});

})

},fail(err){

console.log(err)

},complete(){

console.log(‘complete’)

}

})

------ 这样就可以了

回到顶部