I think there may be a bug in the Native File plugin with
writeFile(path, fileName, text, options)
Documentation say options = true should over write existing file.
replace file if set to true. See WriteOptions for more information.
But it doesn’t seem to work.
Here are console logs for a backup of meeting files. The first time through, the file doesn’t exist and write works fine.
The second time through, the backup file exists and I want to simply overwrite it. But write fails.
In backupMeetings of AppComponentesPage main.js:144466
MeetingMetricsBackup.txt doesnt exist main.js:144477
Directory List: [] main.js:144490
Backup Successful. File is MeetingMetricsBackup.txt main.js:144480
In backupMeetings of AppComponentesPage main.js:144466
Directory List:
[FileEntry]
main.js:144490
MeetingMetricsBackup.txt exists main.js:144477
Failed to write file:
Code is:
let testFile = File.checkFile(this.storageDirectory, “MeetingMetricsBackup.txt”).then(_ => console.log(‘MeetingMetricsBackup.txt exists’)).catch(err => console.log(‘MeetingMetricsBackup.txt doesnt exist’));
// Write file -- should work even if file exists.
File.writeFile(this.storageDirectory, "MeetingMetricsBackup.txt", meetingLists, true).then((success) => {
console.log("Backup Successful. File is MeetingMetricsBackup.txt")
}, (error) => {
console.log("Failed to write file: ");
});
} else{
alert("Meeting Lists are undefined. Perhaps No meetings to backed up.")
}
});
File.listDir(this.storageDirectory, "").then(function (success) {
console.log("Directory List: ", success);
}, function (error) {
console.log("Unable to list Directory ");
});
Work around is to test for existence and remove, but that shouldn’t be necessary If I am interpreting the App documentation correctly.