Hi,
we often need to update with one datamapper postprocessor script different text file for each record. To do so, the openTextWriter() is within the for loop, to open and close the correct text file to append the data.
Is there a more clever way than the one below to avoid writing the headers IF the file already has lines?
Any ideas are much appreciated, thanks.
for(var i=0;i<data.records.length;i++) {
var filepath = 'C:\\Secure Folder\\Portal\\OneDrive - ΠΑΠΑΔΟΠΟΥΛΟΣ ΑΕ\\INTRUM\\OUT\\'+acsdate+'_'+acscode+'_ACSConnectImport.txt';
var file = openTextWriter(filepath,"ISO-8859-7",1);
file.close();
filecheck = openTextReader(filepath,"ISO-8859-7",1);
if (filecheck.readLine()==null) {
file = openTextWriter(filepath,"ISO-8859-7",1);
file.write(headers);
file.write('\n');
} else { file = openTextWriter(filepath,"ISO-8859-7",1); }
f1 = .......
str = f1+';' + ......;
file.write(str);
file.newLine();
file.close();
}