我收到一封包含zip文件的电子邮件。如何使用Google Apps脚本解压缩这些文件并将其保存到Google云端硬盘上的特定文件夹?以下代码部分可与简单的excel / pdf文件完美配合。
var root = DriveApp.getRootFolder();
for(var i in threads){
var mesgs = threads[i].getMessages();
for(var j in mesgs){
var attachments = mesgs[j].getAttachments();
for(var k in attachments){
var attachment = attachments[k];
var isDefinedType = checkIfDefinedType_(attachment);
if(!isDefinedType) continue;
var attachmentBlob = attachment.copyBlob();
var existingFile = DriveApp.getFilesByName(attachment.getName());
if (existingFile.hasNext()) {
var file = existingFile.next();
file.setTrashed(true);
}
var file = DriveApp.createFile(attachmentBlob);
parentFolder.addFile(file);
root.removeFile(file);
答案 0 :(得分:1)
您可以使用Utilities.unzip()
将文件添加到文件夹。
var attachmentBlob = attachment.copyBlob();
var files = Utilities.unzip(attachmentBlob);
files.forEach(function(file) {
DriveApp.createFile(file)
parentFolder.addFile(file);
root.removeFile(file);
});
我希望这对您有帮助!