uniapp加入了广告之后,点击广告下载的apk使应用占用的存储越来越高,这些文件如何删除。
没有MAC,所以下面仅介绍 Android 环境
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, function(fs) {
const path = fs.root.fullPath const apkFilePath = path.replace('downloads/', 'files/') clearFiles(apkFilePath)
function clearFiles (apkFilePath) { plus.io.resolveLocalFileSystemURL(apkFilePath, function(entry){ const directoryReader = entry.createReader(); directoryReader.readEntries(function(entries) { entries.map(readEntry => { if (readEntry.isFile) { const fileName = readEntry.name const filePath = readEntry.fullPath plus.io.resolveLocalFileSystemURL(filePath, function(file) { file.remove() }) } else if (readEntry.isDirectory) { clearFiles(readEntry.fullPath) } }) }, function(e) { console.lo('error', e) }) }, function(e){ console.lo('error', e) }) } },function(e) { console.lo('error', e) });
|