Reputation: 565
Checking to see if a txt file already exists. If it exists I want to open and append. If !exist I want to create, open, write. I don't know how to append the file...
Here's my code so far:
function writeReport(path, reportText) {
var reportFile = new File(path + "/font_report.txt");
if(reportFile.exists){
alert('file already exists');
reportFile.open("w");
reportFile.write(reportText);
reportFile.close();
}
else{
var RCF_file = new File(reportFile);
RCF_file.open("w");
RCF_file.write(reportText);
RCF_file.close();
}
alert('Report Complete');
}
The code in the if(exists) is obviously the same as in the else{} - not sure what it should be...
Upvotes: 0
Views: 3866
Reputation: 565
To append the file it needs to pass the append mode...
reportFile.open("a");
Upvotes: 1