googledrive Move File Script刚刚开始失败,无法正常工作

时间:2020-07-28 04:21:56

标签: google-apps-script google-drive-api

以下代码每隔4分钟在一次触发器上运行。这会将所有文件(不是文件夹)从我的Google云端硬盘的根目录移到指定目录。 这开始失败,不再起作用。它在第6行function sortByColumnEventsIncidents(e) { const sh=e.range.getSheet(); const sA=["Employee","Report by","Branch"]; if(sh.getName()=='Events/Incidents' && e.range.columnStart==5 && e.range.rowStart==1) { const headerArray=sh.getRange(2,1,1,sh.getLastColumn()).getValues()[0]; const col={}; headerArray.forEach(function(h,i){col[h]=i+1;}); const rg=sh.getRange(3,1,sh.getLastRow()-2,sh.getLastColumn()); if(sA.indexOf(e.value)!=-1) { rg.sort({column:col[e.value],ascending:true}); sh.getRange('A3').activate(); }else{ rg.sort({column:col[e.value],ascending:false}); } } } 上出错 并出现以下错误destination.addFile(file);

Exception: Invalid argument (line 6, file "Code")

谁能看到为什么会这样?

1 个答案:

答案 0 :(得分:-1)

这对我有用:

function MoveFiles(){
  const root=DriveApp.getRootFolder();
  const files=root.getFiles();
  const destination=DriveApp.getFolderById("folderid");
  while (files.hasNext()) {
    var file=files.next();
    destination.addFile(file);
    root.removeFile(file);   
  }
}

我使用触发器对其进行了测试,并且可以正常工作