xx.writeFile wx.getSavedFileList 空

发布于 6 年前作者 juan603093 次浏览最后编辑 6 年前来自 ask

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 回复
ezou
ezou1 楼6 年前

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

qiang26
qiang262 楼5 年前

无语十分钟。。。。。

答案:

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’)

}

})

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