cordova文件插件无法删除文件夹

时间:2017-03-07 04:52:45

标签: cordova angular ionic2

我正在尝试从目标文件夹中删除文件。所以,最初我从该目标文件夹中获取了所有文件的列表,并使用我的文件列表检查了该目标文件,该条件成功。

fileToTrash(file) {
    console.log("going to delet a file", file);
    console.log("going to delet a file", file.audio.nativeURL);
    console.log("going to delet a file", file.audio.name);//returns a file name with .mp3 extension
    File.listDir(cordova.file.externalRootDirectory, 'folder/Audios')
    .then((allFiles) => {
        // do something
        console.log("we have audio files", allFiles[0].name);
        for (var i = 0; i < allFiles.length; i++) {
            console.log("name", allFiles[i].name);
            if (allFiles[i].name == file.audio.name) {
                console.log("condition true",allFiles[i].name, file.audio.name)
                var path = cordova.file.externalRootDirectory + 'folder/Audio/';
                var filename = allFiles[i].name;
                File.removeFile( path, filename)
                .then(function (success) {
                    // success
                    console.log("success",success);
                }, function (error) {
                    // error
                    console.log(path);
                    console.log(allFiles[i].name);
                    console.log("error",error);
                });
            }
        }
    }).catch((err) => {
        // do something
        console.log("file listing err", err)
    });
}

但在File.removeFile(path, filename)上,它会转移到错误块。有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

传递路径file:///storage/emulated/0/folder/Audios/

时出现了一个愚蠢的错误
 var path = cordova.file.externalRootDirectory + 'folder/Audio/';

正确的文件路径包含“音频”而不是“音频”。