Skip to content

Instantly share code, notes, and snippets.

@meoso
Last active March 7, 2022 20:24
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 meoso/38c6bb84e450906e0593b9c020e82d3e to your computer and use it in GitHub Desktop.
Save meoso/38c6bb84e450906e0593b9c020e82d3e to your computer and use it in GitHub Desktop.
KeepForeverFALSE__ALLLLL -- for https://script.google.com/ and gDrive file revision "KeepForever" modification
function setRevisionPurge() {
//var search = '(title contains .BBL) or (title contains .bbl)';
var files = DriveApp.getFiles(); //DriveApp.searchFiles(search);
while (files.hasNext()) {
var file = files.next();
var fileName = file.getName();
var fileId = file.getId();
try {
var revisions = Drive.Revisions.list(fileId).items;
console.log('fileName '+fileName+' fileID '+fileId);
// no need to unset revision 0 because it's the "current"; therefore, for i = 1 to max
for (var i = 1 ; i < revisions.length ; i ++) {
console.log(' revisions['+i+'] '+revisions[i].id+' dated: '+revisions[i].getModifiedDate()+' -- keep was: '+revisions[i].pinned);
if (revisions[i].pinned) {
var rclone = revisions[i];
rclone.pinned = false;
console.log(' LETS NOT KEEP '+'revision['+i+']'+' of '+fileName);
var request = Drive.Revisions.update(rclone, fileId, revisions[i].id);
}
}
} catch (e) {
Logger.log(e.message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment