I've set up a google drive folder structure for work with 2 levels of sub-folders. e.g.
Main folder
-Area 1
---Excluded area
-Area 2
---Excluded area
I need an email notification each time a file is modified to ensure other users have to most up to date data. I've found a script online which mostly works but I need it to be able to check within the sub-folders for modifications which this script doesn't do. Any help would be appreciated. Thanks, Amanda
function GoogleDriveModifiedFiles(){
// Folder ID "XXXXXXXxxXXXwwerr0RSQ2ZlZms" of the folder to monitor for changes
var folderID = '"' + "0Bwz931NfDj3HUnhTVXBuc1lqMTg" + '"';
// Email Configuration
var emailFromName ="Work Google Drive (Do Not Reply)";
var emailSubject = "Work Google Drive content has been modified";
var emailBody = "<br>You are receiving this email because a folder/file shared with you on Google Drive has been modified, click on the link to view new content<br>"
var emailFooter = "Any questions please contact [email protected]";
var folderSearch = folderID + " " + "in parents";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var email = sheet.getRange("E1").getValue();
var timezone = ss.getSpreadsheetTimeZone();
var today = new Date();
var oneDayAgo = new Date(today.getTime() - 1 * 60 * 1000);
var startTime = oneDayAgo.toISOString();
var search = '(trashed = true or trashed = false) and '+ folderSearch +' and (modifiedDate > "' + startTime + '")';
var files = DriveApp.searchFiles(search);
var row = "", count=0;
while( files.hasNext() ) {
var file = files.next();
var fileName = file.getName();
var fileURL = file.getUrl();
var lastUpdated = Utilities.formatDate(file.getLastUpdated(), timezone, "dd-MM-yyyy HH:mm");
var dateCreated = Utilities.formatDate(file.getDateCreated(), timezone, "dd-MM-yyyy HH:mm")
row += "<li>" + lastUpdated + " <a href='" + fileURL + "'>" + fileName + "</a></li>";
sheet.appendRow([dateCreated, lastUpdated, fileName, fileURL]);
count++;
}
if (row !== "") {
row = "<p>" + count + " file(s) changed:</p><ol>" + row + "</ol>";
row += emailBody+"<br>" + "<br><small> "+emailFooter+" </a>.</small>";
MailApp.sendEmail(email, emailSubject, "", {name: emailFromName, htmlBody: row});
}
}