从谷歌插件下载多个文件

时间:2014-10-03 14:49:11

标签: google-apps-script return

您好我正在尝试从google文件夹中下载多个文件作为txt。我正在使用谷歌脚本。到目前为止,我的代码将成功从文件夹下载第一个文件但它停止并不会下载该文件夹中的其余文件。谢谢

function doGet() {


var folder = DriveApp.getFolderById('FolderKeyHere')

var files = folder.getFiles();
   while (files.hasNext()) {
      var file = files.next();
      Logger.log(file.getName());
      var id = file.getId(); 

     var doc = DocumentApp.openById(id);

     var string = doc.getBody().getText();

     var output = ContentService.createTextOutput();
     output.setMimeType(ContentService.MimeType.TEXT);
     output.setContent(string);
     output.downloadAsFile(file.getName());

     return output;

   };

};

1 个答案:

答案 0 :(得分:0)

这是不可能的,return output;实际上会“返回”应用程序,当然会退出while循环。

我认为如果没有用户操作,你将无法循环这种过程。

您可以构建一个小Ui,每按一次按钮就会有一个按钮来逐个下载文件,但我想这不是您想要的。

为什么不在驱动器中创建所有文件,压缩单个zip文件中的所有文件,下载zip然后从驱动器中删除文件和zip?

编写的时间稍长 - 我认为 - 在单次下载中获取多个文件的唯一可用工作流程。