I have a working application that creates a file. I am looking for a way to delete files from a cordova application after several hours of work. I can not make it work.
here is the code for creating and deleting files:
function crea(){
alert(cordova.file.externalDataDirectory);
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dir) {
alert("got main dir",dir);
dir.getFile("log1.txt", {create:true}, function(file) {
alert("got the file", file);
});
});
}
function del(){
var relativeFilePath = cordova.file.dataDirectory;
var filename = "log1.txt";
alert(relativeFilePath);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
fileSystem.root.getFile(relativeFilePath + filename, {create:false}, function(fileEntry){
fileEntry.remove(function(file){
alert("File removed!");
},function(){
alert("error deleting the file " + error.code);
});
},function(){
alert("file does not exist");
});
},function(evt){
alert(evt.target.error.code);
});
}
Regards.
source
share