Google apps script - iterate folder and subfolder

后端 未结 3 1122
走了就别回头了
走了就别回头了 2020-12-10 06:14

I want to iterate through the tree structure of the folder in Google Drive using google apps script. The code below is listing some of the folders but not all. Can you advic

3条回答
  •  清歌不尽
    2020-12-10 06:46

    This should do the trick:

    function start() {
     folder = DriveApp.getFolderById("0B_5HSTQXtXmsOHBzcnc2dTlkRFU") 
     listFolders(folder)
    }
    
    function listFolders(folder) {
      //starting point, we come here from start() or from the bottom of this function
    
    
    
      //check the name
      var name = folder.getName();
    
      if (name.match("TITL")) { 
         folder.addEditor("somePerson@gmail.com"); 
      }
    
      //now see if this folder has subfolders
      var subfolders = folder.getFolders();
    
      //if it has, we call this function again
      while (subfolders.hasNext()) {    
        listFolders(subfolders.next());
      }
    
    }
    

提交回复
热议问题