Run a Google Script when a file is added to a folder
Asked Answered
S

1

2

I would like a google script to run every time a file is added to a specific folder. Can this be done? Currently, I have a trigger that causes the script to run every minute, however this is not always fast enough.

Search answered 7/4, 2018 at 22:10 Comment(4)
There's not a trigger for that, if that's what you're hoping. How are things getting into the folder, and do you have any control over that?Oidium
Yes, I have control over how they are being addedSearch
Have you looked at Drive REST API, the Changes resource?Greeson
Here is a workaround solution for whoever is still watching this thread.Mccully
B
0
    function mainFunction(){
  const folderID = 'folderID'; //provide here the ID of the folder
  const newCounter = countFiles(folderID);
  const runCode = checkProperty(folderID, newCounter);
  
  if(runCode){
   // here execute your main code
   // 
    console.log("I am executed!");
   //
  }
}
Bala answered 14/11, 2022 at 12:58 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Retraction

© 2022 - 2024 — McMap. All rights reserved.