Creating a zip file inside Google Drive with Apps Script

前端 未结 4 1350
深忆病人
深忆病人 2020-11-30 05:26

I have a folder in Google Drive folder containing few files. I want to make a Google Apps Script that will zip all files in that folder and create the zip file inside same f

4条回答
  •  孤城傲影
    2020-11-30 05:35

    There's no API reference indeed. You could open an issue request regarding this on Apps Script issue tracker. But deducing from what the code-completion shows, here is my understanding:

    var folder = DocsList.getFolder('path/to/folder');
    var files = folder.getFiles();
    var blobs = [];
    for( var i in files )
      blobs.push(files[i].getBlob());
    var zip = Utilities.zip(blobs, 'newFiles.zip');
    folder.createFile(zip);
    

    But I have not tested this code, so I don't know if it will work. Also, it may work only for files not converted to Google's format, or maybe only for those or a subset of it. Well, if you try it out and find something, please share here with us. One limit that you'll sure face is the filesize, it will probably not work if the zip file gets "too" big... yeah, you'll have to test this limit too.

提交回复
热议问题