Modification points:

  • In your script, file is FileIterator.
  • In your if statement, is used 2 times. In this case, 1st is different from 2nd If the file of the filename name.csv are existing only one file, when 2nd is run, an error occurs. I thought that This might be the reason of your issue.
  • When you want to move the processed file to the trash box, it is required to use setTrashed for the 1st

When above points are reflected to your script, it becomes as follows.

Modified script:

function importCSV () {
  const folder = DriveApp.getFolderById("xyz");
  const file = folder.getFilesByName("name.csv");
  if (file.hasNext()) {
    const f =; // Added
    const csvString = f.getBlob().getDataAsString(); // Modified
    const csvData = Utilities.parseCsv(csvString);
    const lastRow = csvSheet.getLastRow();
    f.setTrashed(true); // Modified


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top