title: How to list all files in google drive in a folder with a set name?
body: <p>I have a folder in my drive which houses multiple "Client" folders. Each client folder has the same structure which includes a folder that contains completed invoices (called "Completed invoices").</p>
  
  <p><a href="https://i.stack.imgur.com/ABGKd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ABGKd.png" alt="folder structure"></a></p>
  
  <p>I need a way to iterate through all the folders named "Completed Invoices" and list in a google sheet the spreadsheet Id's in those folders so I can loop through those files later and extract data from them.</p>
  
  <p>Ive found multiple code sources that work but only on the first level - i.e. it will list the files in the agents/clients folder, but it will not go into the sub folders. E.g. see code below</p>
  
  <pre><code>function listFilesInFolder() {
  
     var sheet = SpreadsheetApp.getActiveSheet();
     sheet.appendRow(["Name", "Date", "Size", "URL", "Download", "Description", "Type"]);
  
      var folder = DriveApp.getFoldersByName("FOLDER ID GOES HERE");
      //Logger.log(folder);
      var contents = folder.getFiles();
  
      var cnt = 0;
      var file;
  
      while (contents.hasNext()) {
          var file = contents.next();
          cnt++;
  
          Logger.log(file);
          Logger.log(cnt);
  
              data = [
                  file.getName(),
                  file.getDateCreated(),
                  file.getSize(),
                  file.getUrl(),
  ,
              ];
  
              sheet.appendRow(data);
  
  
  
      };
  };
  </code></pre>