Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
Save Gmail attachment to SHARED Google Drive

Goal: Update code below to save attachments to a "Test" folder within "Shared drive"

So far I've been successful in saving attachments to "My Drive" using the gmail2gdrive script found on https://github.com/ahochsteger/gmail2gdrive

This script uses DriveApp.getRootFolder() to find the root folder, but does not look at shared drives.
I have the "Drive" Advanced Service set up and am able to at least view up to 10 folders in the Shared Drive using getSharedDrives(), but have been unsuccessful updating the code to transfer files to a shared drives.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Move a file from MyDrive to Shared Drive

function movefileToSharedDrive() {
  const file = DriveApp.getFileById('');//fileid
  const fldr = DriveApp.getFolderById('');//shared drive id
  Drive.Files.update({"parents": [{"id": fldr.getId()}]}, file.getId(), null, {"supportsAllDrives":true});
}

Drive API Version 2 needs to be enabled

about 4 years ago · Santiago Gelvez Report

0

The Folder Drive ID can be found in the URL extension: Folder Drive ID

Use the folders' Drive IDs (from above) to fill in the appropriate section of the code below (Copies files from desired folder into the shared folder):

function movefileToSharedDrive() {
  makeCopy("", ""); //("From My Drive ID", "To Shared Drive ID")
}

function makeCopy(srcFolderId, dstFolderId) {
  var srcFolder = DriveApp.getFolderById(srcFolderId);
  var dstFolder = DriveApp.getFolderById(dstFolderId);
  var files = srcFolder.getFiles();
  while (files.hasNext()) {
    var file = files.next();
    var f = file.makeCopy(dstFolder);
    if (file.getMimeType() == MimeType.GOOGLE_APPS_SCRIPT) {
      Drive.Files.update({"parents": [{"id": dstFolderId}]}, f.getId());
    }
  }
}
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!