Skip to content

Instantly share code, notes, and snippets.

@leoherzog
Last active May 20, 2021 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoherzog/6b81ecc7eb89393e0dd80f7291c8c6c1 to your computer and use it in GitHub Desktop.
Save leoherzog/6b81ecc7eb89393e0dd80f7291c8c6c1 to your computer and use it in GitHub Desktop.
Export Classic Google Sites Attachments to Google Drive Folder
// Go to script.google.com, click "New Project", copy and paste this code in, and click "▷ Run" in the toolbar
function run() {
let sites = SitesApp.getAllSites('example.com');
console.log('Total number of sites: ' + sites.length);
sites = sites.filter(site => {
try {
return site.getOwners().map(owner => owner.getEmail()).includes('you@example.com') ||
site.getEditors().map(editor => editor.getEmail()).includes('you@example.com') ||
site.getViewers().map(viewer => viewer.getEmail()).includes('you@example.com');
}
catch(e) {
return false;
}
});
console.log('Sites you\'re a part of: ' + sites.length);
let root = DriveApp.createFolder('Sites Export ' + Utilities.formatDate(new Date(), 'America/Detroit', 'yyyy-MM-dd-hh-mm-ssz'));
for (let site of sites) {
console.log('Creating ' + site.getTitle().trim());
let folder = DriveApp.createFolder(site.getTitle().trim()).moveTo(root);
let attachments = site.getAttachments();
for (let attachment of attachments) {
DriveApp.createFile(attachment.getBlob()).moveTo(folder);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment