Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 移动文件时,脚本首先选择哪个文件?_Google Apps Script - Fatal编程技术网

Google apps script 移动文件时,脚本首先选择哪个文件?

Google apps script 移动文件时,脚本首先选择哪个文件?,google-apps-script,Google Apps Script,我有一个GoogleApps脚本,可以将一个GoogleDrive文件移动到另一个GoogleDrive地图。由于基于时间的触发器,每4小时发生一次。有人知道它选择移动哪个文件吗?文件具有随机名称,因此应随机移动。但是,脚本似乎只移动最后上载的文件 对于上下文:我将脚本与IFTTT结合使用 试试这个: function moveRandomly(s,t) { var files=DriveApp.getFolderById(s).getFiles(); var fA=[]; whil

我有一个GoogleApps脚本,可以将一个GoogleDrive文件移动到另一个GoogleDrive地图。由于基于时间的触发器,每4小时发生一次。有人知道它选择移动哪个文件吗?文件具有随机名称,因此应随机移动。但是,脚本似乎只移动最后上载的文件

对于上下文:我将脚本与IFTTT结合使用

试试这个:

function moveRandomly(s,t) {
  var files=DriveApp.getFolderById(s).getFiles();
  var fA=[];
  while(files.hasNext()){fA.push(files.next().getId());}
  var file=DriveApp.getFileById(fA[Math.floor(Math.random()*fA.length)]);
  var destination=DriveApp.getFolderById(t);
  destination.addFile(file);
  var pull=DriveApp.getFolderById("SourceFolderId");
  pull.removeFile(file);
}

欢迎来到StackOverFlow,请借此机会参加并学习如何,以及。
function moveRandomly(s,t) {
  var files=DriveApp.getFolderById(s).getFiles();
  var fA=[];
  while(files.hasNext()){fA.push(files.next().getId());}
  var file=DriveApp.getFileById(fA[Math.floor(Math.random()*fA.length)]);
  var destination=DriveApp.getFolderById(t);
  destination.addFile(file);
  var pull=DriveApp.getFolderById("SourceFolderId");
  pull.removeFile(file);
}