Google Drive Duplicate File Cleanup Automation - n8n Workflow

Automate Google Drive file management using this powerful n8n workflow. Detect, flag, or trash duplicate files based on MD5 checksums and creation time.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users looking to maintain a clean and optimized Google Drive storage.
System administrators needing a reliable duplicate file cleanup solution.
Developers seeking robust file operation n8n templates.
Anyone familiar with creating custom logic using an n8n node.

Overview

Managing large volumes of files often results in storage being wasted by exact duplicates. This robust n8n workflow solves this problem by using file metadata, specifically the MD5 checksum, to guarantee accurate identification of identical files. The automation starts with an n8n trigger watching a specified folder. Users can configure the desired behavior: choosing to keep the first or last version of the file, and deciding whether to permanently trash the duplicates or merely flag them by prepending "DUPLICATE-" to the filename. This sophisticated use of the n8n node ecosystem allows for highly customized and preventative maintenance of cloud storage, providing a necessary solution missing from native Google Drive features. This n8n workflow is a perfect example of advanced file management.

How it Works


  1. Trigger and Configuration: The process begins with the Google Drive n8n trigger, which activates upon new file creation in a designated folder. A subsequent Set n8n node (Config) establishes essential configuration parameters: keep (which file version to keep, default last) and action (what to do with the duplicate, default flag).

  2. File Retrieval and Filtering: The workflow uses a Google Drive n8n node (Working Folder) to pull all relevant files from the specified folder. It then uses a Filter n8n node (Drop Google Apps files) to discard proprietary Google files (Docs, Sheets) as they lack the necessary md5Checksum used for accurate duplicate checking.

  3. Deduplication Logic: A Switch n8n node (Keep First/Last) routes the items based on the configured keep parameter. Custom Code n8n node logic is then applied to iterate through the file metadata, sorting them by creation time and marking true duplicates based on matching md5Checksum values. The unwanted version is marked as isDuplicate = true.

  4. Isolate Duplicates: A subsequent Filter n8n node isolates only those items marked as duplicates, ensuring only cleanup actions proceed.

  5. Execution Action: A final Switch n8n node (Trash/Flag Duplicates) determines the execution path based on the user's action variable.

If action is trash, the duplicate file is sent to the Google Drive trash using another Google Drive n8n node.
If action is flag, an If n8n node checks if the file is already prefixed with "DUPLICATE-". If not, a Google Drive n8n node renames the file; otherwise, a NoOp n8n node ensures no redundant action occurs. This prevents re-flagging already processed items in this n8n workflow.

Installation Guide


  1. Import the n8n Workflow: Download the provided JSON data and import it into your n8n instance via the 'New' -> 'Import from JSON' option. This imports the complete n8n workflow structure.

  2. Credential Setup: You must configure Google Drive OAuth2 API credentials. Ensure that the Google Drive Trigger, Working Folder, and all subsequent Google Drive n8n node instances are connected to your authenticated Google Drive account.

  3. Trigger Configuration: In the Google Drive Trigger n8n node, define the specific folder ID you wish to monitor for new file creations. Ensure the polling interval is set appropriately.

  4. Set Cleanup Policy: Open the Config Set n8n node and adjust the core variables:

keep: Set to first or last (determines which creation time version is retained).
action: Set to trash (sends the duplicate to trash) or flag (renames it).

  1. Activation: Once configured, activate the n8n workflow to begin automatically monitoring for and processing duplicate files.

Node Details

Google Drive Trigger: The starting n8n trigger. Configured to monitor a specified folder for newly created files, initiating the automation. Key setting is the Folder To Watch.
Config (Set n8n node): Defines crucial parameters (keep, action) that dictate how the rest of the n8n workflow manages the duplicates.
Working Folder (Google Drive n8n node): Retrieves all necessary file metadata (ID, name, md5Checksum, createdTime) from the target folder, filtered by file owner.
Drop Google Apps files (Filter n8n node): A critical filter that excludes files that do not contain a comparable md5Checksum (e.g., Google Docs, Sheets).
Deduplicate Keep Last / Keep First (Code n8n nodes): These Code n8n node blocks implement the core logic. They sort the files by creation date and use custom JavaScript to compare md5Checksums, marking redundant files with the isDuplicate flag.
Trash/Flag Duplicates (Switch n8n node): Directs the flow based on the cleanup policy set in the Config n8n node.
Send Duplicates to Trash (Google Drive n8n node): Executes the deletion, moving the identified duplicate file to the Google Drive trash bin.
Google Drive (Rename) (Google Drive n8n node): If flagging is chosen, this n8n node updates the file name by prepending "DUPLICATE-", offering a non-destructive cleanup option.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by
Ventsislav Minev
Ventsislav Minev

IT professional and n8n enthusiast

Featured*