During our migration to Team Drives, we had a folder that was migrated twice. The first time was interrupted, and we now have thousands of duplicate folders with nothing in them. I would like to delete or at least remove any folders on a specific team drive that are completely empty. I found an old script that I tried to modify below:
function delEmptyFolders() {
var folders = DriveApp.getFolders();
var ss = SpreadsheetApp.create("folderslist");
while (folders.hasNext()) {
var folder = folders.next();
var files = folder.getFiles();
var childfolders = folder.getFolders();
var filecount = 0;
var foldercount = 0;
while (childfolders.hasNext()){
var childfolder = childfolders.next();
foldercount ++;
}
while (files.hasNext()){
var file = files.next();
filecount ++;
}
ss.appendRow([folder.getId(),folder.getName(),filecount, foldercount]);
if (filecount == 0 && foldercount == 0){
folder.setTrashed(true);
}
}
}
My question is how do I get this script to run on a specific team drive, or better yet, in a specific folder on a team drive?
Original Question answered in comments - new script below - followup question in comments
Thank you in advance for your help and my apologies as I am not well experienced in coding or scripts.
function starEmptyFolders() {
var folders = DriveApp.getFolderById('ID').getFolders();
var ss = SpreadsheetApp.create("test");
while (folders.hasNext()) {
var folder = folders.next();
var files = folder.getFiles();
var childfolders = folder.getFolders();
var filecount = 0;
var foldercount = 0;
while (childfolders.hasNext()){
var childfolder = childfolders.next();
foldercount ++;
}
while (files.hasNext()){
var file = files.next();
filecount ++;
}
////////////////////
var child = childfolders;
var subFolders = child.getFolders();
while(subFolders.hasNext()) {
var subFolder = subFolders.next();
var subfoldercount = 0;
subfoldercount ++}
///////////////////////////
}
ss.appendRow([folder.getId(),folder.getName(),filecount, foldercount, subfoldercount,]);
if (filecount == 0 && foldercount == 0){
folder.setStarred(true);