I have a project in which I want to delete a set of sheets in order to clean up and start over. I have a script that does this, but I am also adding some backup sheets that I do not want to delete. In other words the sheets not to delete changes as I add these backup sheets.
function DeleteAllSheets() {
const sheets = ss.getSheets();
//for (i = 0; i < sheets.length; i++)
sheets.forEach(function (item, i) {
switch (sheets[i].getSheetName()) {
case "roster":
case "template":
case "Test":
break;
default:
ss.deleteSheet(sheets[i]);
}
})
}
I have another script that creates backups of the roster sheet from time to time and names the backups "Backup Test (Date)" or where the name of the back up sheet name always begins with 'Backup Test' but has a different date. Instead of having to go into the script to add these backups from being deleted, is there a way with the 'case' function to use some logic like "contains Backup Test" or "begins with Backup Test" to keep these from being deleted.