admin管理员组

文章数量:1314239

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 .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 :)

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./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 :)

Share Improve this question edited Feb 19, 2013 at 17:01 Emil 7,25618 gold badges80 silver badges135 bronze badges asked Feb 19, 2013 at 16:52 Megan SimeMegan Sime 1,2672 gold badges16 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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

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

本文标签: javascriptPhoneGap File Remove not workingStack Overflow