Automatically delete file from Google Drive trash

sam juni picture sam juni · Sep 23, 2015 · Viewed 16k times · Source

There are several articles, but I am not able to put a code together to run it successfully.

One article I have looked at: Permanently delete file from google drive

I would like to automatically delete the Google Drive trash folder items every hour or so. Prefer every 10 minutes. Google need to implement this useful feature.

Answer

Rivero picture Rivero · Sep 25, 2015

As stated on [ Permanently delete file from google drive ], you can enable the Drive API in order to get access to the method, through Appscript. Take a look at appscript quotas to ensure that your implementation can support calling the API every ten minutes.

You can use this solution:

function createTimeDrivenTriggers() {
  ScriptApp.newTrigger('emptyThrash')
      .timeBased()
      .everyHours(1)
      .create();
}

function emptyThrash()
{
  Drive.Files.emptyTrash();
}