我正在尝试从目标文件夹删除文件。因此,最初,我从该目标文件夹中列出了所有文件的列表,并用我的文件列表检查了该目标文件,该条件成功了。
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)
上,它移至错误块。有人可以帮我吗?
通过路径file:///storage/emulated/0/folder/Audios/
var path = cordova.file.externalRootDirectory + 'folder/Audio/';
正确的文件路径包含"音频",而不是"音频"。