Home > Enterprise >  Error: getBlob is not defined when geting latest CSV file in a specified folder
Error: getBlob is not defined when geting latest CSV file in a specified folder

Time:01-22

I am trying to repurpose a scrcipt that gets all CSV files in a spicified folder to get only the lattest CSV file in a folder

Original from here Google Script to copy all csv files in a GDrive Folder as new sheets in existing 'master' Google sheet

I get the error Error: getBlob is not defined here let vs = Utilities.parseCsv(DriveApp.getFileById(arr[0].id),getBlob().getDataAsString());

What I have so far

How to correct the error?

Thanks

function runScript2() {
  const ss = SpreadsheetApp.getActive()
  const folder = DriveApp.getFolderById("1Hxxx");
  const files = folder.getFiles();
  const arr = [];

  while (files.hasNext()) {
    let file = files.next();  
 arr.push({name:file.getName(),id:file.getId(),mimetype:file.getMimeType(),date:file.getDateCreated()});
    //let fn = file.getName();
    //let fileID = file.getId();
    //let fileType = file.getMimeType();
  };
    //console.log(arr)
    arr.sort((a,b)=> {
      return new Date(b.date).valueOf() - new Date(a.date).valueOf();
    });
    //console.log(arr)

    let vs = Utilities.parseCsv(DriveApp.getFileById(arr[0].id),getBlob().getDataAsString());
    let sh = SpreadsheetApp.getActiveSheet();
    sh.clearContents();
    sh.getRange(1,1,vs.length, vs[0].length).setValues(vs);
}

CodePudding user response:

I think you have a typo. Change the ,getBlob() to .getBlob()

let vs = Utilities.parseCsv(DriveApp.getFileById(arr[0].id),getBlob().getDataAsString());

To

let vs = Utilities.parseCsv(DriveApp.getFileById(arr[0].id).getBlob().getDataAsString());
  • Related