n8n

How to Automate Google Drive Duplicate Cleanup?

Keep your Google Drive tidy by finding and handling duplicate files in a chosen folder. You can keep the first or last copy and either send the extras to trash or mark them with a clear DUPLICATE prefix. Ideal for teams that share upload folders and need clean storage without manual checks.

The flow starts with a Google Drive trigger that checks the selected folder every 15 minutes for new uploads. A folder scan gathers files at depth level one and removes Google Docs types, since those are links and cannot be compared like real files. A setting decides whether to keep the earliest or latest file, and a code step sorts by created time to tag duplicates. A filter passes only items marked as duplicates. Another setting chooses the action path to either delete the extras or rename them. A safety check skips files already marked so nothing gets renamed twice. Owner and folder values come from the trigger to avoid acting on files you do not own. An Edit Fields step keeps the flags consistent, and a NoOp step cleanly ends already flagged items.

Connect a Google Drive account in n8n Cloud, set your poll time and folder, and confirm the owner matches the files. Start with the flag option so you can review the output before turning on trash. Remember that Google Drive keeps trashed files for 30 days, so recovery is possible. Expect faster reviews, fewer mistakes, and less wasted space in busy shared folders.

What are the key features?

  • Google Drive trigger checks a selected folder every 15 minutes for new uploads
  • Working Folder search lists files at depth level one for safe, focused cleanup
  • Filter removes Google Docs, Sheets, Slides, and other non binary files
  • Config step sets keep first or keep last and choose trash or flag actions
  • Code steps sort by created time and tag duplicates based on your keep choice
  • Edit Fields normalizes the duplicate flag for consistent filtering
  • Action switch deletes duplicates or renames them with a clear prefix
  • Safety check avoids renaming files that were already marked as duplicates
  • Delete action sends items to Google Drive trash with 30 day retention

What are the benefits?

  • Reduce manual duplicate checks from hours to minutes
  • Cut storage waste by removing extra copies of files
  • Lower risk of deleting the wrong file with clear keep rules
  • Maintain an audit trail by adding a DUPLICATE prefix
  • Scale cleanup in busy folders with automatic polling

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Google Drive. See the Tools Required section above for links to create accounts with these services.
  3. Open the Google Drive Trigger node. In the Credential to connect with field, click Create new credential. Choose Google Drive OAuth2, follow the on screen steps, and grant access. Name the credential clearly, for example Google Drive Main.
  4. In the Google Drive Trigger, set Poll Times to your preferred interval and choose the target folder. For first tests, pick a small folder instead of the root.
  5. Open the Config step. Set keep to first or last, and set action to flag or trash. Leave owner and folder values linked to the trigger unless you need to override them.
  6. Open the Working Folder node. Confirm it points to the same folder and searches files at depth level one. Keep this limit if you want to avoid nested folders.
  7. Check the Drop Google Apps files filter. It should exclude Docs, Sheets, Slides, and other Google formats that cannot be compared as binary files.
  8. Run a test: upload two copies of the same file into the folder. Wait for the next poll or click Execute workflow to test immediately.
  9. Review results. If action is flag, duplicates should have the DUPLICATE prefix. If action is trash, check the Google Drive trash where files remain for 30 days.
  10. Troubleshoot if nothing happens: confirm the credential has access to the folder, make sure the connected account owns the files, verify the chosen folder, and check the n8n execution logs for skipped Google Docs or owner mismatches.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Google Drive

Sign up

Drive API: $0 (no additional cost; quota-limited)

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.