PhoneGap File Delete Not Working
I am creating a main application that has PhoneGap pretty strong as I am trying to determine what it can / cannot do. I got to the scene where I am looking to delete a file that was loaded in the application, but that doesn't work. most of the code i used is http://docs.phonegap.com/en/2.4.0/cordova_file_file.md.html#FileEntry ;
function removefile(){
fileSystem.root.getFile("readme.txt", {create: false, exclusive: false}, gotRemoveFileEntry, fail);
}
function gotRemoveFileEntry(fileEntry){
console.log(fileEntry);
fileEntry.file(gotFile, fail);
entry.remove(success, fail);
}
function success(entry) {
console.log("Removal succeeded");
}
function fail(error) {
console.log("Error removing file: " + error.code);
}
and I named it with HTML;
<button onclick="removefile();">remove file</button>
Is there something wrong with the code? I do not see it.
By the way, I am coding for iOS and using JavaScript, HTML and PhoneGap / Cordova in Xcode.
I am new to iPhone development so any help would be greatly appreciated :)
+3
source to share
2 answers
Your code is a little off. Try:
function removefile(){
fileSystem.root.getFile("readme.txt", {create: false, exclusive: false}, gotRemoveFileEntry, fail);
}
function gotRemoveFileEntry(fileEntry){
console.log(fileEntry);
fileEntry.remove(success, fail);
}
function success(entry) {
console.log("Removal succeeded");
}
function fail(error) {
console.log("Error removing file: " + error.code);
}
+5
source to share
Old entrance. The API may have changed, but I was able to do it this way:
function success(entry) {
console.log("Removal succeeded");
}
function fail(error) {
console.log("Error removing file: " + error.code);
}
resolveLocalFileSystemURL(cordova.file.dataDirectory + 'assets/icons/test.png', function(entry) {
console.log(entry);
entry.remove(success, fail);
})
0
source to share