我很难理解phonegap/cordova的file
api文档。
如何找到应用程序临时文件夹的路径,然后列出/删除内容而不删除文件夹本身?
这与从设备图库中拉取照片时创建临时图像文件的删除有关。
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);
}
如果你想删除临时图片,你可以使用清理选项
navigator.camera.cleanup( cameraSuccess, cameraError );