Reputation: 1311
I'm having a hard time figuring out the phonegap/codrova file
api docs.
How does one find the path to the application's tmp folder and then list/delete the contents without deleting the folder itself?
This specifically relates to the deletion of temporary image files created when I pull a photo from the device's image gallery.
Upvotes: 3
Views: 5927
Reputation: 53301
If you want to delete the temporary images, you have the cleanup option
navigator.camera.cleanup( cameraSuccess, cameraError );
Upvotes: 0
Reputation: 1118
This function uses the cordova file plugin to delete a specific file from the tmp folder
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'));
}
You could tweak it a bit to find all files first and remove them. Something like this
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);
}
Upvotes: 7