S
S
SerJik_Z2022-02-25 07:47:10
Google Drive
SerJik_Z, 2022-02-25 07:47:10

How to exclude a folder from Google app script search in Google drive?

Good afternoon! This script allows you to display all the folders and what is in them.

function getFolderList() {
var folders = DriveApp.getFolders();
while (folders.hasNext()) {
  var folder = folders.next();
  var files = folder.getFiles();
  Logger.log(folder.getName());
  
  while(files.hasNext()){
    var file = files.next();
    Logger.log(file.getName());
  }  
}
}

How to exclude a folder and what is in it if its id or name is "123" for example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2022-02-25
@SerJik_Z

Obviously you need to get the name or id of the folder, and check what is not equal to the condition

function getFolderList() {
  const folders = DriveApp.getFolders();
  while (folders.hasNext()) {
    let folder = folders.next();
    
    folder = folder.getId()
    if (folder != '123') {

      const files = folder.getFiles();
      Logger.log(folder.getName());

      while (files.hasNext()) {
        const file = files.next();
        Logger.log(file.getName());
      }
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question