-
-
Save mr-nit/f744f46d77038c5b5fb17aeb2618fa9d to your computer and use it in GitHub Desktop.
Google App script to remove files created more than 90 days from multiple directories
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 DeleteOldFiles() { | |
| var Folders = new Array( | |
| 'insert dir ID', //Entry | |
| 'insert dir ID', //Garage | |
| 'insert dir ID' //Kitchen | |
| ); | |
| var Files; | |
| Logger.clear(); | |
| for each (var FolderID in Folders) { | |
| Folder = DriveApp.getFolderById(FolderID) | |
| Files = Folder.getFiles(); | |
| while (Files.hasNext()) { | |
| var File = Files.next(); | |
| if (new Date() - File.getDateCreated() > 90 * 24 * 60 * 60 * 1000) { | |
| File.setTrashed(true); // Places the file int the Trash folder | |
| //Drive.Files.remove(File.getId()); // Permanently deletes the file | |
| Logger.log('File: ' + ' "' + Folder + "/" + File.getName() + '" moved to Trash..'); | |
| } | |
| } | |
| } | |
| var recipient = '[email protected]'; | |
| var subject = 'Homeboy folder has been cleaned up' | |
| var body = Logger.getLog(); | |
| if(body != '') { | |
| MailApp.sendEmail(recipient, subject, body); | |
| Logger.log('⚒ eMail sent.'); | |
| } | |
| if(body == '') { | |
| Logger.log('⚒ No files were removed today.'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment