I would like to write a google apps script to trash every empty folder into my google drive, which method / property should I use to examine the current folder (I can write a cycle) is really empty, id est without any file or any other nested folder inside?
And, what happens if you trash a folder which has some files linked to? Do those files get trashed to or do they get orphaned (if linked to just on folder, of course)?
Thank you.
– cordialmente,
tiziano solignani, da Mac http://blog.solignani.it
This is what I coded after the first useful answer, I just inserted pagination:
function FindEmptyFolders() {
var pageSize = 200;
var folders = null;
var token = null;
var i = null;
Logger.clear()
do {
var result = DocsList.getAllFoldersForPaging(pageSize, token);
folders = result.getFolders();
token = result.getToken();
for (var i = 0; i < folders.length; i++) {
for(n=0;n<folders.length;++n){
if(folders[n].getFiles().length==0 && folders[n].getFolders().length==0){
folders[n].setTrashed(true)
Logger.log(folders[n].getName())
Logger.log(folders[n].getUrl())
}
}
}
} while (folders.length == pageSize);
MailApp.sendEmail('solignani@solignani.it', 'Script eliminazione folders vuoti Log', Logger.getLog());
}