建议使用:根据文件路径来清除文件
try {
const fs = wx.getFileSystemManager()
fs.accessSync(`${wx.env.USER_DATA_PATH}/bjxc`)
} catch(err) {
console.error(err)
}
try {
fs.mkdirSync(`${wx.env.USER_DATA_PATH}/example`, false)
} catch(e) {
console.error(e)
}
const fileName = new Date().valueOf()
const filePath = wx.env.USER_DATA_PATH + '/bjxc/' + fileName + '.mp4'
wx.downloadFile({
url: downloadUrl,
filePath: filePath,
success: resolve,
fail: reject
})
try {
const fs = wx.getFileSystemManager()
const res = fs.unlinkSync(filePath)
console.log('success',res)
} catch(err) {
console.log('err',err)
}
try {
const fs = wx.getFileSystemManager()
fs.readdir({
dirPath: wx.env.USER_DATA_PATH + '/bjxc',
success:res => {
console.log('readdir',res)
res.files.forEach(item => {
try {
const fs = wx.getFileSystemManager()
const res = fs.unlinkSync(wx.env.USER_DATA_PATH + '/bjxc/' + item )
console.log('success',res)
} catch(err) {
console.log('err',err)
}
})
},
fail: err => {
console.log('readdir',err)
}
})
} catch(err) {
console.log('err',err)
}
快速处理方案:让用户在设置-->通用-->存储空间-->清理缓存