title: Automatically Delete Files from Google Drive Older than n days - "getFolderById" issue
body: <p>I'm trying to delete files and folders older than 7 days in a specific Team Drive (not in the whole Google Drive).</p>
  
  <p>To accomplish this I tried to merge what I read here:
  <a href="https://stackoverflow.com/questions/28618964/apps-script-automatically-delete-files-from-google-drive-older-than-3-days-g">Apps Script - Automatically Delete Files from Google Drive Older than 3 Days - Get List of Files</a></p>
  
  <p>I don't have enough rep to add a comment there so that's why I'm opening a new thread. Here you can find my ripoff from <a href="https://stackoverflow.com/users/1588938/user1588938">user1588938</a>:</p>
  
  <pre><code>function getOldFileIDs() {
    var fileIDs = [];
    // Old date is 30 days
    var oldDate = new Date().getTime() - 3600*1000*24*30;
    var cutOffDate = Utilities.formatDate(new Date(oldDate), "GMT", "yyyy-MM-dd");
  
    // Get folderID using the URL on google drive
    var folder = DriveApp.getFolderById('XXXXXXX');
    var files = folder.searchFiles('modifiedDate &lt; "' + cutOffDate + '"');
  
    while (files.hasNext()) {
      var file = files.next();
      fileIDs.push(file.getId());
      Logger.log('ID: ' + file.getId() + ', Name: ' + file.getName());
    }
    return fileIDs;
  };
  
  function deleteFiles() {
    var fileIDs = getOldFileIDs();
    fileIDs.forEach(function(fileID) {
      DriveApp.getFileById(fileID).setTrashed(true);
    });
  };
  </code></pre>
  
  <p>I'm stuck with 'getFolderById' function because I suppose it doesn't apply to a Team Drive root but only works for folders inside of it. 
  Indeed, when I look at the logs I can see that the output for:</p>
  
  <pre><code>  var folder = DriveApp.getFolderById('this-is-my-team-drive-id');  
  </code></pre>
  
  <p>is a generic: <em>[18-07-30 06:34:49:146 PDT] Team Drive</em> and not the name of the Team Drive I chose.</p>
  
  <p>I can't go any further with the script because of this.</p>
  
  <p>Any hint on how to list every file and subfolder in a Team Drive using <em>searchFiles</em>?</p>
  
  <p>This solution might apply but it works for a folder inside a Team Drive and not on the root of the Team Drive:
  <a href="https://stackoverflow.com/questions/48293530/browse-files-in-google-team-drive">browse files in google team drive</a></p>
  
  <p>Thanks!</p>