I need an example for deleting all files in a google drive folder

I have a scenario that receives emails. It will add a row to a google sheet using data found in the email body, create a folder using the email’s subject as the filename, then take the two attachments and upload them to the created folder. Let’s call that the main branch.

It will also check if a folder of the same name already exists. If such a folder is found, it will fork to a branch that skips the folder creation and uploads to the existing folder. Let’s call this the 2nd branch.

In the case of the 2nd branch, I want to delete the old contents of the folder before uploading the new attachments. This is to save file storage space. I can’t figure out how to do it, and I’m hoping someone can help.

I managed to make a version of the scenario that deletes the folder and recreates it before uploading, but this will pose problems in the long run.

@rdcrssd You can achieve it easily.

Use Search Files and Folders module and put a search string from your email.

Apply a filter on the results and use Google Drive Batch API to Delete all the output files and folders.

1 Like