Thursday, January 19, 2023

delete old files - Google Apps Script

https://stackoverflow.com/questions/66060908/google-script-delete-files-within-a-folder-based-on-the-last-modified-date

gives an unattributed code snippet, but seems to be OK. (I've not yet implemented this.) 

https://gist.github.com/mbierman/f29f8e7846d2824a81c4e74c5522a34b

uses getDateCreated() instead of searchFiles() & modifiedDate. This second script also has an elegant way of emailing using Logger.getLog()

If we want to permanently delete instead of sending to trash, which we might want to do in case of rapidly filling up drives and so on, there is the Files API delete function, https://developers.google.com/drive/api/v2/reference/files/delete#examples which might be called from Apps script by enabling the Drive API on the LHS and Drive.Files.delete(fileid).

No comments:

Post a Comment