Gather All Google Drive Files of a Certain Type and Change Owner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const newOwner = 'blah@example.com'; | |
const fileTypesToTransfer = ['application/vnd.google-apps.form']; // https://developers.google.com/drive/api/guides/mime-types | |
function changeOwnership() { | |
console.log('Gathering all files in Drive of type ' + fileTypesToTransfer.join(',') + '...'); | |
let fileIterator = DriveApp.searchFiles(fileTypesToTransfer.map(x => 'mimeType = "' + x + '"').join(' or ')); | |
let files = []; | |
while (fileIterator.hasNext()) { | |
files.push(fileIterator.next()); | |
} | |
console.log('Transferring ownership of ' + files.length + ' files...'); | |
for (let file of files) { | |
try { | |
file.setOwner(newOwner); | |
} | |
catch(e) { | |
console.error('Problem updating ownership for the file ' + file.getName() + '. Continuing...'); | |
} | |
Utilities.sleep(100); // .1 secs, avoiding rate limiting | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment