Automated Google Drive Folder Path Creator - n8n Workflow

A specialized n8n workflow designed to recursively create nested Google Drive folders from a defined path string, optimizing file organization and providing the final folder ID for subsequent file uploads. Get this n8n template now.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users needing to programmatically enforce deep, standardized folder structures in Google Drive.
System administrators or developers who integrate folder creation into automated data archival or project setup processes.
Anyone looking for a reusable n8n node component for robust Google Drive operations.
Organizations utilizing n8n templates for efficient cloud storage management.

Overview

Managing complex, deeply nested folder structures in Google Drive can be cumbersome when automated processes require specific, multi-level directory trees. This specialized n8n workflow solves this by taking a single path string (e.g., Projects/2024/Q4/Client_Data) and intelligently ensuring that every folder in that hierarchy exists. This particular n8n workflow is designed to be called by an Execute Workflow Trigger from another flow, acting as a powerful subroutine. It checks for the existence of each component folder and only creates it if necessary, dramatically streamlining file management and ensuring that subsequent tasks in your parent n8n flow can immediately access the correct final folder ID for operations like file uploads.

How it Works

This powerful n8n workflow is intended to be called by an Execute Workflow Trigger from a parent process. The primary input requires the starting googledrivefolderid (e.g., 'root') and the desiredpath string.


  1. Initialization: Upon triggering, a Code n8n node (Split the desired path) takes the input path string (like A/B/C) and splits it into an array ([A, B, C]).

  2. Existence Check: The flow enters a loop. A Google Drive n8n node (Check if top folder exists) queries the current parent folder to see if the folder corresponding to the first element of the array (e.g., 'A') already exists.

  3. Conditional Creation: An If n8n node (If top folder doesn't exist) checks the search result. If the folder is not found, the Create new subfolder Google Drive n8n node creates it. If found, the creation step is skipped.

  4. Parameter Update: A Code n8n node (Set parameters for next run) performs two crucial tasks: it updates the parent ID to the ID of the newly created or found folder, and it removes the processed folder name from the array using JavaScript's shift() method.

  5. Loop Control: Another If n8n node (If path has been completely created) checks if the path array is empty. If it is not empty, the flow loops back to process the next folder in the path (e.g., 'B').

  6. Final Output: Once the array is empty, signaling the complete creation of the nested structure, the workflow terminates, returning the ID of the deepest created folder using a Set n8n node. This ensures the output can be consumed immediately by the parent n8n workflow.

Installation Guide

To deploy this reusable n8n template:


  1. Import: Copy the provided JSON data and paste it directly into your n8n canvas using the 'New' -> 'Import from JSON' feature.

  2. Credentials: Update the Google Drive n8n node credentials (Check if top folder exists and Create new subfolder) with your authenticated Google Drive account.

  3. Execution Mode: Note that the primary n8n trigger is the Execute Workflow Trigger, meaning you must save this workflow and then call it from another parent n8n workflow for production use.

  4. Testing: Use the Manual Trigger and Dummy input data Set n8n node to test the logic with sample path strings (remember to disable the Execute Workflow Trigger when using the Manual Trigger). Ensure your Google Drive account has the necessary permissions to create folders in the specified root or parent folder ID.

Node Details

This n8n workflow utilizes several key nodes to manage the recursive folder creation:

Execute Workflow Trigger: The essential n8n trigger for running this workflow as a sub-process, allowing other parent n8n workflows to call it with required inputs (googledrivefolderid and desiredpath).
Set (Dummy input data): An n8n node used purely for providing test inputs when testing manually. Sets the start ID (e.g., 'root') and the path string (e.g., 'testXavier/2024/Q4').
Code (Split the desired path): This Code n8n node splits the input path string by the / delimiter into a manageable array of folder names.
Google Drive (Check if top folder exists): A critical Google Drive n8n node configured to search for a folder name (the first item in the path array) within the current parent folder ID.
If (If top folder doesn't exist): This conditional n8n node directs the flow, proceeding to creation only if the query from the previous Google Drive n8n node returns an empty result.
Google Drive (Create new subfolder): The core creation n8n node. It creates the folder using the current parent ID.
Code (Set parameters for next run): This Code n8n node handles the recursive logic, setting the newly created folder ID as the new parent ID and removing the first item from the remaining path array to prepare for the next loop iteration. This makes the n8n workflow highly flexible.
If (If path has been completely created): Checks if the path array is empty to determine if the recursion should stop or continue looping back to the path creation step.


  • Set (Return the ID of the last folder): The final n8n node that outputs the unique ID of the deepest folder created, concluding the n8n workflow's execution.

Related n8n Workflows

Free

Nodes: 7 Nodes
Updated: December 26 2025
View all
Created by
Xavier
Xavier

Featured*