PhoneGap ::删除文件

时间:2016-07-20 21:30:59

标签: cordova

我已经花了两天时间试图猜测为什么我无法从持久性的officegap临时文件夹中删除文件(在windows 10文件中:/// temporary /)。

这是我用于阅读/写作/删除的课程:

var app_file = {

fileContent: null,
params: null,

init: function(params) {
    if(typeof params != "undefined") {
        app_file.params = params;
    }
    window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, app_file.gotFS, app_file.fail); 
}, 

gotFS: function(fileSystem) {
    app_file.fileSystem = fileSystem;
    if(typeof app_file.params.action != "undefined") {
        app_file[app_file.params.action]();
    }
},

dispatcher: function(params, options) {
    app_file.params = params;
    app_file.fileSystem.root.getFile(app_file.params.filename, options, app_file[app_file.params.action], app_file.fail);
},

write: function(fileEntry) {
    fileEntry.createWriter(app_file.WriterHandler, app_file.fail);
},

WriterHandler: function(writer) {
    writer.seek(writer.length); //append to the end
    writer.write(app_file.params.content);
},

read: function(fileEntry) {
    fileEntry.file(function(file){
        var reader = new FileReader();
        reader.onloadend = function(evt){
            $('#storage-tree').append($('<li />').html(evt.target._localURL + ': ' + evt.target.result)); 
        };
        reader.readAsText(file);                        
    },app_file.fail);
},

viewLog: function() { 
    directoryEntry = app_file.fileSystem.root;

    var directoryReader = directoryEntry.createReader();
    directoryReader.readEntries(app_file.readDirectory, app_file.fail);
}, 

readDirectory: function(entries){
    var sOutput = "";
    for(var i=0; i < entries.length; i++) {
        app_file.fileSystem.root.getFile(directoryEntry.fullPath + entries[i].name,{create:false},app_file.read,app_file.fail);
        entries[i].remove(function(){
                            console.log("File removed!");
                        },function(){
                            console.log("error deleting the file " + error.code);
                    });
    }                            
},

fail: function(error) {
    console.log('app_file error: ' + error.code);
}

};

每次执行viewLog方法时,我都会得到一个文件列表和一个控制台消息“File removed”,但实际上文件永远不会被删除,因为在调用方法时总会列出文件。

有什么建议吗?

谢谢, 哈维

0 个答案:

没有答案