I have a bunch of Google Docs that I want to concatenate into a fresh new doc. Basically I want to do the equivalent of the Unix command:
cat 1.txt 2.txt 3.txt >4.txt
I can't seem to figure out the best way to do this from the Apps Scripts documentation. Would anyone happen to know?
I tried the following:
// ... code omitted
var entries = [];
while (files.hasNext()) {
var file = files.next();
var name = file.getName();
if (file.getOwner().getName() != 'My Name') continue
var re = /Pattern I am looking for - \d\d/g;
if (name.match(re) == null) continue;
entries.push( {"Name" : name, "File" : file} );
}
entries.sort(function(a,b) { return a.Name.localeCompare(b.Name); });
// Open the Full.txt file and add each file into it in sequence.
var fullDoc = DocumentApp.create('Full.txt');
entries.forEach(function(e) {
var contents = e.File.getAs('text/plain');
// Haven't yet gotten to sticking contents into the target file
// because content retrieval itself fails with the message:
// "Converting from application/vnd.google-apps.document to text/plain
// is not supported. (line 51, file "DocMerge")"
return;
});
Thanks.
-av