const fs = require('fs');
const utils = require('./utils');

function append(entries, dist) {
  let title;

  entries.forEach(entry => {
    title = utils.formatDate(entry.creationDate);

    fs.appendFile(`${dist}/${title}.txt`, entry.text, err => {
      if (err) {
        console.error(`Failed exporting ${entry.creationDate}: ${err}`);
      }
    });
  });
}

module.exports = {
  append
};

@@ -99,16 +99,28 @@
 t title;
+%0A  let path;
 %0A%0A  entr
@@ -196,27 +196,19 @@
 e);%0A
-%0A
     
-fs.appendFile(
+path = 
 %60$%7Bd
@@ -225,18 +225,91 @@
 le%7D.txt%60
-, 
+;%0A%0A    if (fs.existsSync(path)) %7B%0A      fs.appendFile(path, %60%5Cn%5Cn----%5Cn%5Cn$%7B
 entry.te
@@ -310,16 +310,18 @@
 try.text
+%7D%60
 , err =%3E
@@ -325,24 +325,26 @@
  =%3E %7B%0A      
+  
 if (err) %7B%0A 
@@ -338,24 +338,26 @@
  if (err) %7B%0A
+  
         cons
@@ -392,28 +392,20 @@
 $%7Bentry.
-creationDate
+uuid
 %7D: $%7Berr
@@ -419,18 +419,22 @@
     
-%7D%0A
+  %7D%0A  
     %7D);%0A
   %7D)
@@ -429,16 +429,77 @@
     %7D);%0A
+    %7D else %7B%0A      fs.writeFileSync(path, entry.text);%0A    %7D%0A
   %7D);%0A%7D%0A

Improve file existence checking