Megan Sime
Megan Sime

Reputation: 1267

PhoneGap File Remove not working

I am building up a basic app which features PhoneGap pretty heavily as i am trying to determine what it can/can't do. i have gotten to the stage where i am looking to remove a file that has been downloaded on the app, but it won't work. most of the code i've used is from 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 have called it using the HTML;

    <button onclick="removefile();">remove file</button>

is there something wrong with the code? i can't see it.

By the way I'm coding for iOS and using JavaScript, HTML and PhoneGap/Cordova in Xcode.

I'm fairly new to iPhone development so any help would be great thanks a lot :)

Upvotes: 4

Views: 11137

Answers (2)

Manu
Manu

Reputation: 3452

Old entry. The API may have changed, but I was able to do it like this:

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);
})

Upvotes: 0

Simon MacDonald
Simon MacDonald

Reputation: 23273

Your code is slightly 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);
}

Upvotes: 5

Related Questions