I made this script to list all subfolders of a given folder, so later I can look up values in another worsheet. But the script is not picking up all the folders. Why's that
function ListaPasta() {
var foldername= 'Main folder name';
var folderlisting = 'folders';
var mainfolder = DriveApp.getFoldersByName(foldername).next();
var folders = mainfolder.getFolders();
var ss = SpreadsheetApp.create(folderlisting);
var sheet = ss.getActiveSheet();
sheet.appendRow( ['Nome'] );
while(folders.hasNext()) {
var folder = folders.next();
var nome = folder.getName();
sheet.appendRow([nome]);
};
}
Edit: I don't want the subfolders of the folders inside the main folder, so I don't need recursion.
The script is not listing all folders and I'm sure of it, because when I look for some folder in the listing (via LOOK functions and using the filter) I can't find it, but if I search in the drive I find it inside the main folder(not as a subfolder of other folders).
Now since the time I posted this question I noticed that when I opened some folders looking for a file it would show the folder as empty, but if I searched for the file name it would find it. After I opened the file and closed it, and then went to the folder and opened it the file would be there. Could be a similar behaviour causing the script to not find some folders?
Not sure if relevant, but the main folder is part of a shared drive.