Google Drive Nested Folder File Extraction - n8n Workflow

Automate file retrieval from deeply nested Google Drive folders using this robust n8n workflow. Efficiently list all file IDs from a complex directory structure.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Users needing a comprehensive inventory of files across deeply nested Google Drive folders.

  • Developers or system administrators who require a list of file IDs for migration or bulk processing.

  • n8n users looking for advanced examples of recursive workflow execution and file handling.

  • Anyone seeking a reliable n8n workflow to manage cloud storage operations.

Overview

Managing files in Google Drive can be complicated, especially when dealing with deeply nested folder structures. This complex n8n workflow is designed to overcome that limitation by automating the traversal of directories. It provides an elegant solution for aggregating all file identifiers from a root folder, regardless of how many layers of subfolders exist.

This robust n8n workflow utilizes recursion via the Execute Workflow n8n node to ensure all branches of the folder structure are searched. By implementing this detailed logic, you can ensure complete coverage and reliably extract every file ID needed for subsequent operations. This is an essential n8n template for advanced cloud storage automation.

How it Works

This n8n workflow begins with the Start Execution n8n trigger, initiating the process, typically run manually or called by an external system.


  1. Initial Retrieval: The workflow first uses the Google Drive n8n node to search for immediate child folders of the designated parent ID.

  2. Nesting Check: An IF n8n node (If parent folder has nested folders or not) checks if any sub-folders were found.

  3. Recursive Traversal (If Nested): If nested folders exist, the workflow executes a sub-workflow using the Start sub-execution n8n node. This recursive pattern ensures that the entire folder tree is mapped. The results are collected and processed by the Get all folder ids Code n8n node, which extracts all relevant folder IDs.

  4. Flat Traversal (If Flat): If no nested folders are found, the initial parent folder ID is directly prepared for processing using a SET n8n node (Return parent folder id).

  5. Iteration and File Extraction: Regardless of the path, the collected folder IDs are passed to the Split In Batches n8n node (Loop Over folder ids). This node iterates through every single folder ID.

  6. File Retrieval: Inside the loop, another Google Drive n8n node (Get all files inside a folder) fetches all files associated with the current folder ID.

  7. Final Output: The Return all file ids SET n8n node compiles the final list of file IDs extracted from all folders, providing the comprehensive output of this powerful n8n workflow.

Installation Guide

To implement this n8n template, follow these steps:


  1. Import: Copy the provided JSON data and paste it into your n8n instance using the 'Import Workflow' function.

  2. Google Drive Credentials: Locate the Google Drive n8n node and update the credentials. You must create a Google Drive OAuth or API key credential within n8n that has read access to the relevant folder structures.

  3. Configuration: The Get children folders from folder id n8n node requires the initial Parent Folder ID to be set in its configuration, likely via a workflow input parameter or a fixed value.

  4. Sub-Workflow Setup (Critical): Since this n8n workflow uses the Execute Workflow n8n node (Start sub-execution), ensure that the necessary target workflow (likely this same workflow JSON) is active and properly referenced by ID or name in the configuration for the recursive call to function correctly.

  5. Activation: Save and activate the n8n workflow. You can test the n8n trigger manually.

Node Details

Start Execution (n8n trigger): Initiates the entire n8n workflow manually or when called by a parent workflow.
Get children folders from folder id (Google Drive n8n node): The primary data source operation. It searches for sub-folders within the designated parent folder ID.
Key Configuration: Operation set to 'Get All' children; Resource set to 'Folder'.
If parent folder has nested folders or not (IF n8n node): Controls the flow, routing execution based on whether the initial Google Drive call returned any sub-folders (checking for nesting).
Start sub-execution (Execute Workflow n8n node): Executes the recursive logic, calling the same n8n workflow to handle deeper nested folders, crucial for traversing the whole directory tree.
Get all folder ids (Code n8n node): Processes the incoming data items (which may include results from recursive calls) to consolidate and return a clean list of all folder IDs found throughout the structure.
Loop Over folder ids (Split In Batches n8n node): Prepares the list of collected folder IDs for sequential processing, ensuring the file extraction is performed on every identified directory.
Get all files inside a folder (Google Drive n8n node): Within the iteration loop, this n8n node retrieves all files contained within the specific folder ID passed by the Split In Batches node.
Key Configuration: Resource set to 'File', Operation set to 'Get All' files, filtering by the parent ID.
Return all file ids (Set n8n node): The final step of the n8n template, used to collect and output the results—the comprehensive list of file IDs.

Related n8n Workflows

Paid

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by

Software Engineer with over 3+ years of experience in full-stack development.

Featured*