Empty shared drive trash folder

Problem

No button to delete everything on a shared drive. Deleting one-by-one is not a viable option, there is too many files.

Environment

  • Google Drive web
  • Google Script

Solution

  1. Open https://script.google.com.
  2. Click New project.
  3. Name the script project in the title.
  4. Delete the code "function myFunction() {}" and add the next script:
    function myFunction() { var optionalArgs={'driveId':'THE TEAM DRIVE ID', 'includeItemsFromAllDrives':true, 'corpora': 'drive', 'supportsAllDrives': true, 'q':'trashed = true' } var trashed=Drive.Files.list(optionalArgs).items; for(var i=0;i<trashed.length;i++){ Drive.Files.remove(trashed[i].id, {'supportsAllDrives':true}) } }  
  5. Replace THE TEAM DRIVE ID with the Shared Drive ID.
  6. Click Services +  in the left navigation panel.
  7. Select Drive API and click ADD
  8. Save Google Apps Script project using the button in the toolbar.
  9. Click Run.
  10. It will ask for your permissions in the first run, click Allow.

Cause

There is not an option to empty the trash folder for Shared Drives.