DriveApp.getFolders() get folders not from my Google Drive

Skip to first unread message

Heeg Ru

Feb 1, 2020, 8:13:40 AM2/1/20
to Google Apps Script Community
I write a little script to find folder "_images" on my  google drive

   var folders = DriveApp.getFolders();
while (folders.hasNext()) {
var folder =;
if(folder.getName()=='_images'){ idf=folder.getId();    Logger.log("folder _images if found");  break;}

it find folder "_images" not only on my drive, but all folders "_images"  I have access to (people share it for me).
how to make this script search  my folder only on my Drive, and not on drives of other people? 

jiit mahe2

Feb 1, 2020, 8:20:40 AM2/1/20
     Based on cache,  if you use userCache it can maintain individual  mail account otherwise use scriptCache the cache data deflect other shared people also. 
    Sorry for my bad english.. 

You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Alan Wells

Feb 1, 2020, 8:28:21 AM2/1/20
to Google Apps Script Community
You can search for folders with specific attributes.  In the example below, the search query will search for folders only owned by you with a specific title.

//See documentation at:

var folders = DriveApp.searchFolders('title contains "_images" and "me" in owners');
var folder;

while (folders.hasNext()) {
if(folder.getName() == '_images'){
= folder.getId();
Logger.log("folder _images if found - ID: " + idf);  

Clay Smith

Feb 1, 2020, 8:30:03 AM2/1/20
to Google Apps Script Community
Get the folder’s owner. You can check if it’s the same email associated with the account. If the folder have been added to the Drive but is owned by another it will not see the folder as one you are looking for.

var folders = DriveApp.getFolders();
while (folders.hasNext()) {
var folder =;
if(folder.getName()=='_images' && folder.getOwner().getEmail==Session.getActiveUser().getEmail()){ idf=folder.getId(); Logger.log("folder _images if found"); break;}
Reply all
Reply to author
0 new messages