Automate Google Drive Duplicate File Cleanup with n8n

Struggling with duplicate files cluttering your Google Drive? This n8n workflow automatically detects duplicates and either flags or trashes them, saving you hours of manual cleanup. Learn how to deploy an effective duplicate file management system with easy configuration options.
googleDriveTrigger
code
googleDrive
+5
Workflow Identifier: 1222
NODES in Use: Set, Google Drive Trigger, Google Drive, Filter, Code, Switch, If, No Operation
Automate Google Drive cleanup with n8n

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What This Workflow Does

This workflow finds duplicate files in a set Google Drive folder.
It solves the problem of having many copies of the same file stored together.
The outcome is fewer duplicates, either marked or moved to trash automatically.

The workflow runs every 15 minutes and looks for new files created in the folder.
It ignores Google Docs, Sheets, and other app files that don’t have direct file content.

It uses the MD5 checksum, a unique code for file content, to find duplicates.
Then it either renames duplicates by adding a “DUPLICATE-” prefix or sends duplicates to trash.

The user picks whether to keep the oldest or newest file.
Already flagged duplicates are not renamed again.


Tools and Services Used


Inputs, Processing Steps, and Output

Inputs

  • New files created in a specific Google Drive folder.
  • User settings for which file to keep: oldest or newest.
  • User settings for action: rename duplicates or trash duplicates.

Processing Steps

  • The Google Drive Trigger polls every 15 minutes for new files in the folder.
  • The workflow fetches all owned files in that folder excluding Google Apps files.
  • Files are sorted by creation date based on the user choice to keep first or last.
  • MD5 checksums identify which files have the same contents (duplicates).
  • Duplicates are either renamed to have a “DUPLICATE-” prefix or sent to trash.
  • Files already renamed with “DUPLICATE-” are skipped to avoid renaming loops.

Outputs

  • A Google Drive folder free of duplicate files or with duplicates flagged.
  • Automatic cleanup saves user time and reduces manual errors.

Beginner Step-by-Step: How to Use This Workflow in n8n

Download and Import Workflow

  1. Click the Download button on this page to save the workflow file.
  2. Inside the n8n editor, select “Import from File” and upload the downloaded file.

Configure Workflow Settings

  1. Add Google Drive OAuth2 credentials in n8n if not done already.
  2. Update the folder ID inside the Google Drive Trigger to the folder to watch.
  3. Set the owner email in the Set node named Config.
  4. Choose whether to keep the first or last file and whether to flag or trash duplicates in Config.

Test and Activate

  1. Run the workflow once with test files to check that duplicates are detected and handled.
  2. If the test is successful, activate the workflow for regular use.

This workflow can also work on a self-host n8n instance. For help with self-host n8n, check online resources.


Customization Ideas

  • Change the keep preference between oldest or newest files in the Set Config node.
  • Switch the action from flagging to trashing duplicates in the same Set node.
  • Adjust the folder filter in the Google Drive node to check wider areas or the whole drive.
  • Modify the polling interval in the Google Drive Trigger to check more or less often.

Troubleshooting

Problem: No files detected by the Google Drive Trigger

Cause: Wrong folder ID or missing permissions may stop file detection.

Solution: Double-check the folder ID and Google Drive OAuth2 permission scopes.
Try uploading a test file to verify trigger works.

Problem: Duplicates are not flagged or trashed

Cause: Misconfiguration in keep or action parameters or incorrect renaming format.

Solution: Verify values in the Set node Config exactly match “first” or “last” for keep and “flag” or “trash” for action.
Make sure the renaming prefix “DUPLICATE-” is applied correctly.


Pre-Production Checklist

  • Check Google Drive OAuth2 credentials are valid and allowed to read and update files.
  • Confirm the watched folder ID is correct in the Google Drive Trigger.
  • Test the trigger by uploading a new file to that folder.
  • Run workflow on sample files to confirm duplicates are caught and handled right.
  • Backup important files before running workflow live to prevent data loss.

Deployment Guide

After testing, activate the workflow in n8n.
Keep an eye on workflow execution logs for errors.

If trashing duplicates, review the Google Drive trash folder regularly to recover files if wrongly deleted during the 30-day retention.


Summary

✓ Saves time by automating duplicate detection and cleanup in Google Drive.

✓ Reduces errors from manual checking and accidental version confusion.

✓ Flexible options to either rename or trash duplicate files based on user preference.

✓ Easy to configure and run inside n8n with clear step-by-step setup.


Automate Google Drive cleanup with n8n

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

By default, this workflow scans only one specified folder. To check subfolders, the folder filter in the Google Drive node must be adjusted to include nested folders.
Files sent to Google Drive trash are kept for 30 days before permanent deletion. They can be recovered during this period.
The workflow targets files owned by a specified user in specific folders. Additional setup is required to fully support shared drives.
Check the ‘keep’ and ‘action’ parameter values in the Config node. Confirm that the renaming prefix ‘DUPLICATE-‘ matches the workflow’s expectations.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.