Cordova删除文件

Mah*_*iba 6 cordova

我有一个创建文件的工作应用程序.我正在寻找一种方法,可以在工作几个小时后从cordova应用程序中删除文件.我似乎无法使其发挥作用.

这是创建和删除文件的代码:

function crea(){
    alert(cordova.file.externalDataDirectory);
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dir) {
        alert("got main dir",dir);
        dir.getFile("log1.txt", {create:true}, function(file) {
            alert("got the file", file);

        });
    });
        }



    function del(){
var relativeFilePath = cordova.file.dataDirectory;
var filename = "log1.txt"; 
alert(relativeFilePath);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
  //  alert(fileSystem.root.fullPath);
    fileSystem.root.getFile(relativeFilePath + filename, {create:false}, function(fileEntry){
        fileEntry.remove(function(file){
            alert("File removed!");
        },function(){
            alert("error deleting the file " + error.code);
            });
        },function(){
            alert("file does not exist");
        });
    },function(evt){
        alert(evt.target.error.code);
});

}
Run Code Online (Sandbox Code Playgroud)

最好的祝福.

Mah*_*iba 12

我弄明白了:

function del() {

    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dir) {

        dir.getFile("log1.txt", {create: false}, function (fileEntry) {
            fileEntry.remove(function (file) {
                alert("file removed!");
            }, function (error) {
                alert("error occurred: " + error.code);
            }, function () {
                alert("file does not exist");
            });
        });
    });

}
Run Code Online (Sandbox Code Playgroud)

谢谢

  • 您的错误处理程序需要传递"错误"才能使其正常工作. (6认同)