Google apps script - iterate folder and subfolder

后端 未结 3 1117
走了就别回头了
走了就别回头了 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

    To access the sub folders, you can do in this way,

    function getSubFolders(parent) {
      parent = parent.getId();
      var childFolder = DriveApp.getFolderById(parent).getFolders();
      while(childFolder.hasNext()) {
        var child = childFolder.next();
        Logger.log(child.getName());
        getSubFolders(child);
      }
      return;
    }
    
    function listFolders() {
      var parentFolder = DriveApp.getFolderById("0B1n6YLYwFmK_dUpzRWhDRXNwdWc");
      var childFolders = parentFolder.getFolders();
      while(childFolders.hasNext()) {
        var child = childFolders.next();
        Logger.log(child.getName());
        getSubFolders(child);
      }
    }
    

提交回复
热议问题