I have a working app that creates a file. I'm looking for a way to remove files from a cordova app after some hours of work. I can't seem to 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){
// alert(fileSystem.root.fullPath);
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);
});
}
Best Regards.
I got it works :
function del() {
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dir) {
dir.getFile("log1.txt", {create: false}, function (fileEntry) {
fileEntry.remove(function (file) {
alert("file removed!");
}, function (error) {
alert("error occurred: " + error.code);
}, function () {
alert("file does not exist");
});
});
});
}
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With