如何快速清空【本地用户文件】
由于用户本地文件共计10m,
一个保存音频的功能,要求在使用前确保用户本地储存空间剩余10m。所以要进行清空。
是否有一个方便方法。
<button type="primary" bindtap="clearUserData">清空用户文件</button> |
Page({ onReady: function (e) { // 创建一个FS对象 this.fsm = wx.getFileSystemManager(); }, clearUserData: function () { const page = this; this.fsm.readdir({ dirPath: `${wx.env.USER_DATA_PATH}/`, success: function (res) { console.log('readdir', res); // 批量删除 res.files.forEach(element => { if (typeof element === 'string') { page.fsm.rmdir({ dirPath: `${wx.env.USER_DATA_PATH}/${element}`, recursive: true, success: function () { console.log('删除文件夹成功', element); }, fail: function (e) { console.log('删除文件夹失败', e, element); wx.removeSavedFile({ filePath: `${wx.env.USER_DATA_PATH}/${element}`, success: function (res) { console.log('删除文件成功'); console.log(res); } }); } }) } }); } }) }}) |
