I am needing to loop through each .CSV file in a source folder and copy the data from each file into a new sheet/tab in one Google Sheets file. I've found a couple of answers related to this topic but I'm getting errors with both code sets. Here's the code I'm attempting to build a solution from:
function appendCSV() {
var file = DriveApp.getFilesByName("myCSVFile.csv").next();
var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow=sheet.getLastRow();
sheet.getRange(lastRow, 1, csvData.length, csvData[0].length).setValues(csvData);
}
Here's the first error I'm getting:
Cannot retrieve the next object: iterator has reached the end. (line 2, file "Code")
I can delete the .next() method from line 2 and then I get another error:
TypeError: Cannot find function getBlob in object FileIterator. (line 3, file "Code")
Can anyone identify what might be going wrong here?