Last active
March 7, 2022 20:24
-
-
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
This file contains hidden or 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
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
NOTE: if the file revision is already past 30 days, i presume it will almost immediately purge, but i have not tested, run with caution.
Thanks to these resources:
https://script.google.com/
https://stackoverflow.com/questions/46082828/how-can-i-use-a-google-script-to-keep-revision-history-in-google-drive-for-files
https://developers.google.com/drive/api/v2/reference/revisions
https://developers.google.com/apps-script/reference/drive/drive-app
https://developers.google.com/drive/api/v2/ref-search-terms?hl=en