Created
August 20, 2018 17:24
-
-
Save mbierman/f29f8e7846d2824a81c4e74c5522a34b 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 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 = 'your_email@address.com'; | |
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