Google Drive Folder Cleanup and Retention
On a schedule, the flow scans Google Drive folders for files older than a retention window or matching cleanup rules, archives them to cold storage (SharePoint/Blob), removes or trashes the originals, and emails an owner a report of what was cleaned. Enforces retention and reclaims Drive space automatically.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
This flow enforces a retention policy on a Google Drive folder. On a daily schedule it lists every file in a watched folder, selects those last modified before a configurable retention cutoff, copies each expired file to Azure Blob cold storage (organized by yyyy/MM), deletes the original from Drive only after the archive copy succeeds, and emails an owner an HTML report of everything that was cleaned.
Why it matters: Drive folders accumulate stale files, raising storage cost and compliance risk. This automation enforces a defined retention window, keeps an immutable off-platform archive, and reclaims Drive space - with a safe archive-before-delete ordering so nothing is lost.
Status: Built as an unmanaged FlowLibs solution. Ships Off (demo). Going live requires only authorizing the three connections and setting the environment-variable values.
Use Case
IT Admins / Operations want stale files in a shared Google Drive folder archived and removed automatically on a retention schedule, with a daily audit report of what was cleaned and where it was archived.
Flow Architecture
Recurrence Daily Cleanup Scan
RecurrenceRuns the cleanup once per day (Day/1, 02:00 PST).
Initialize Retention Days
Initialize Variable (Integer)int(flowlibs_RetentionDays) - retention window.
Initialize Cutoff Date
Initialize Variable (String)addDays(utcNow(), -retentionDays) cutoff timestamp.
Initialize Storage Account
Initialize Variable (String)Blob storage account from env var.
Initialize Archive Path
Initialize Variable (String)Base archive folder path from env var.
Initialize Report Recipient
Initialize Variable (String)Report email address from env var.
Initialize Cleaned Count
Initialize Variable (Integer)Counter of cleaned files (0).
Initialize Cleaned Rows
Initialize Variable (String)HTML row accumulator for the report.
List Drive Files
Google Drive - ListFolderLists items in the watched folder (Id, Name, LastModified, Size, IsFolder).
Filter Old Files
Filter Array (Query)Keeps non-folder files older than the cutoff.
Apply to each Old File
Foreach (sequential)Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_DriveFolderId | String | REPLACE_WITH_GOOGLE_DRIVE_FOLDER_ID | Google Drive folder to scan. |
| flowlibs_RetentionDays | String | 2555 | Retention window in days (parsed to integer). |
| flowlibs_BlobStorageAccount | String | flowlibsdemostorage | Azure Blob storage account (archive target / dataset). |
| flowlibs_BlobArchiveFolderPath | String | /lifecycle-archive | Base folder path in the blob container. |
| flowlibs_CleanupReportRecipient | String | it-admin@yourcompany.com | Email address for the cleanup report. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Google Drive | shared_googledrive | ListFolder GetFileContent DeleteFile |
| Azure Blob Storage | shared_azureblob | CreateFile_V2 |
| Office 365 Outlook | shared_office365 | SendEmailV2 |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Trash vs. hard delete
- DeleteFile removes the original. To keep a Drive recovery window, route to a Trashed sub-folder via a move/rename pattern instead of deleting.
- Multiple folders
- Wrap the List + Filter + loop in an outer Apply-to-each over a comma-split list of folder ids (add a flowlibs_CleanupFolderIds env var).
- Tiered retention
- Use different flowlibs_RetentionDays values per folder, or add rule-based exclusions (e.g. legal hold) in the Filter where clause.
- Dry run
- Comment out (remove runAfter chain to) Delete Original File to run report-only first.
- SharePoint instead of Blob
- Swap Archive To Cold Storage for SharePoint CreateFile if the archive should live in a document library.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Retention days
Parse the retention window to an integer.
EXPR.02Cutoff date
Compute the retention cutoff timestamp.
EXPR.03Old-file filter
Keep non-folder files older than the cutoff.
EXPR.04Archive folder path
Date-organized archive path.
EXPR.05Report row
Build one HTML report row per cleaned file.
Customize & download
Generate a ready-to-import copy of this solution with your environment-variable values baked in — available on Base, Pro, or Team.
Upgrade to customize
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.