Skip to content

Instantly share code, notes, and snippets.

@mbierman
Created August 20, 2018 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mbierman/f29f8e7846d2824a81c4e74c5522a34b to your computer and use it in GitHub Desktop.
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
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