getFolders()

121 views
Skip to first unread message

Craig Heath

unread,
Jul 12, 2022, 4:10:25 PM7/12/22
to Google Apps Script Community
I have a client list, where each client gets a unique folder. I have a script that reads the folders and creates a form. Works well. However, now I want to create a separate folder in the same group of folders where I can move 'inactive folders.' 

However, now my script still reads all the folders and child folders. What can I do to skip reading the inactive client folders in the inactive folder? 

Any thoughts would be appreciated.

Clark Lind

unread,
Jul 13, 2022, 12:40:49 PM7/13/22
to Google Apps Script Community
I don't know if it can't be used in the folderIterator, but consider playing around with something like this:

var folders = DriveApp.getFolders();
while (folders.hasNext()) {
  var folder = folders.next(); 
//this should simply skip the undersired folder (in theory--I haven't tried it)
  if(folder.getId() === "folderIdOfInactiveFolder") {
     continue
  }
}

Craig Heath

unread,
Jul 15, 2022, 9:46:16 AM7/15/22
to Google Apps Script Community
I figured it out. I used the star option to flag all folders that wanted to designate as inactive. Then used the isStarred() function to identify them and create an array of the unstarred folders.

Case closed. 

Craig Heath

unread,
Jul 15, 2022, 9:47:24 AM7/15/22
to Google Apps Script Community
I just saw this, I will try as well...if it works, I won't have to flag the unwanted folders with a star...thanks!

Craig Heath

unread,
Jul 16, 2022, 9:40:02 AM7/16/22
to Google Apps Script Community
The challenge, was, that even though I could move all the older folders to an inactive folder...the DriveApp doesn't see them as being in a separate folder that I could just skip. It still read them all! I had code that skilled the Inactive Folder...but it wouldn't exclude reading those files and adding them to the list. I wish there were better instructions on how these functions behaved and what the output looked like without so much guessing and trial/error!

Clark Lind

unread,
Jul 17, 2022, 1:12:28 PM7/17/22
to Google Apps Script Community
A longer-term solution might be to create the script within a Spreadsheet, and use the sheet as a "meta data" storage tool. Just keep the sheet in the top level folder. Then you can add the folderIds of active folders in one column, and inactiveIds in another column. Then when you run the script, it just grabs the active folderIds into an array and use that array of folderIds instead of a folderIterator.

Just a thought for you.

Craig Heath

unread,
Jul 17, 2022, 6:14:31 PM7/17/22
to Google Apps Script Community
Not bad...I do use that same approach for filling my forms...
Reply all
Reply to author
Forward
0 new messages