我很难搞清楚phonegap / codrova file
api文档。
如何找到应用程序的tmp文件夹的路径,然后列出/删除内容而不删除文件夹本身?
这特别涉及删除从设备的图库中提取照片时创建的临时图像文件。
答案 0 :(得分:6)
此函数使用cordova文件插件从tmp文件夹中删除特定文件
deleteFile: function(fileName) {
var that = this;
if (!fileName) {
console.error("No fileName specified. File could not be deleted.");
return false;
}
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fileSystem){ // this returns the tmp folder
// File found
fileSystem.root.getFile(fileName, {create: false}, function(fileEntry){
fileEntry.remove(function(success){
console.log(success);
}, function(error){
console.error("deletion failed: " + error);
});
}, that.get('fail'));
}, this.get('fail'));
}
您可以稍微调整一下以找到所有文件并删除它们。像这样的东西
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fileSystem){ {
var reader = fileSystem.root.createReader();
reader.readEntries(function(entries) {
var i;
for (i = 0; i < entries.length; i++) {
if (entries[i].name.indexOf(".png") != -1) {
// delete stuff from above could go in here
}
}
}, fail);
}
答案 1 :(得分:0)
如果要删除临时图像,则可以使用cleanup option
navigator.camera.cleanup( cameraSuccess, cameraError );