title: Apps Script - Automatically Delete Files from Google Drive Older than 3 Days - Get List of Files
body: <p>I'm using my Google Drive to store motion detection recordings from my IP cameras at home.  I'm running the following script (slightly modified) to automatically delete files older than 3 days from my Google Drive:</p>
  
  <p><a href="https://stackoverflow.com/questions/14628895/automatically-delete-files-in-google-drive">Automatically delete files in google drive</a></p>
  
  <p>The script is set to run every morning at around 5am.  The problem I'm running into is, when there are too many files to delete, I get an error saying I've exceeded the max write rate.  This is because the set trashed command is contained within a for-loop.  If I add a sleep to slow down the loop, then I get another error saying the script didn't finish in the allowed time.</p>
  
  <p>I could maybe just run it 2 or 3 times, but that's clunky.  </p>
  
  <p>How can I modify this script to have it create a temporary list of the files to be deleted, and when it finally steps out of the loop, execute the delete?  I don't have much experience with GAS language and syntax, so specifics would be really awesome.</p>