I have created a function to remove a specified directory using the cordova-plugin-file plugin. The function itself works correctly and removes the directory, but I am trying to return a success or failure result based on the outcome and am completely stuck.
(function() {
var app = {
...
function removeDirectory(path) {
var result = false;
window.resolveLocalFileSystemURL(path, function(dir, status) {
dir.removeRecursively(function(dir, status) { // Success callback
result = true;
console.log(result); // true
}, function(error) { // Failure callback
console.log('Error removing directory: ' + getFileError(error.code));
});
console.log(result); // false
});
console.log(result); // false
return result;
}
}
})();
resolveLocalFileSystemURL()
and removeRecursively()
both do not return a value.
No matter what I try, result
always ends up being false
. I've even tried using a global (outside of the IIFE) variable but even that doesn't hold its value correctly.
It seems like a variable scope issue but I just don't know how to fix it.