OneDrive Nested Folder Creator with Existence Check - n8n Workflow

Automate robust, nested folder creation in Microsoft OneDrive using this advanced n8n workflow. It includes sequential existence checks and utilizes the n8n datastore.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • System administrators needing reliable, automated provisioning of directory structures in OneDrive.

  • Automation specialists seeking complex examples of loop control and state management within an n8n workflow.

  • Users looking for powerful n8n templates to streamline file organization and avoid duplicate folders.

Overview

Creating deep, nested directory paths programmatically can be challenging, as many APIs, including OneDrive’s, require creating folders one level at a time based on the parent folder's ID. This sophisticated n8n workflow template handles this complexity by acting as a reusable sub-workflow. It accepts a single input path (e.g., Q1Projects/Marketing/CampaignA) and breaks it down for sequential processing. The core intelligence relies on using the n8n datastore to persistently track the parent folder ID across loop iterations. Before creating any folder using a Microsoft OneDrive n8n node, the automation performs a search. This existence check ensures that the n8n workflow only creates necessary folders, saving execution time and maintaining data hygiene. If you need a reliable method to manage complex folder paths automatically, this advanced n8n template is the solution.

How it Works

This n8n workflow operates entirely as a sub-process, designed to be called by an external n8n trigger or node, receiving the target path string as an input variable.


  1. Input and Path Preparation: The n8n workflow starts by receiving the nested folder path. A JavaScript n8n node (Paths) splits this string (e.g., 'A/B/C') into an array of objects, calculating the full path and the required parent path for each segment.

  2. State Reset: The clearParent n8n node, utilizing the n8n datastore, ensures the critical parentID variable is cleared before the loop begins, preventing contamination from previous runs.

  3. Iteration: The folder path segments are split out and looped over using the Loop Over Items n8n node, ensuring each level is processed sequentially.

  4. Existence Check: For the current segment, the Microsoft OneDrive n8n node (Search) attempts to locate the folder by name.

  5. Conditional Logic: The Exists n8n node checks if the folder was found and if its hierarchical parent path matches the path expected for this iteration.

  6. ID Persistence (Found): If the folder exists, the setParentFound n8n datastore node saves the existing folder’s ID as the parentID. The n8n workflow then proceeds to the next level of the loop.

  7. Creation Logic (Not Found): If the folder is missing, the getParent n8n datastore node retrieves the ID of the parent folder (which must have been found or created in the preceding step).

  8. Folder Creation: The Microsoft OneDrive n8n node (Create a folder) uses the retrieved parent ID to successfully create the new nested folder.

  9. ID Persistence (Created): The setParentCreated n8n datastore node stores the newly created folder’s ID, setting the stage for the next folder creation step in the n8n workflow loop.

Installation Guide

To install this robust n8n workflow template, follow these steps:


  1. Import: Copy the provided JSON and import it directly into your n8n instance.

  2. Credentials: This n8n workflow requires valid Microsoft OneDrive OAuth2 credentials. Locate the Search and Create a folder n8n nodes and assign or create your Microsoft Drive account credentials.

  3. Sub-Workflow Usage: This particular n8n workflow is designed to be executed via the 'Execute Workflow' n8n node from a main workflow. The main workflow must pass the nested folder path (e.g., Client_A/Docs/Invoices) as an input variable named folder to the starting 'When Executed by Another Workflow' n8n trigger node.

  4. Activation: Ensure the n8n workflow is active before attempting execution.

Node Details

This n8n template utilizes several powerful n8n node types to achieve complex state management and looping:

When Executed by Another Workflow (n8n trigger):
Function: Serves as the reusable entry point for this sub-workflow, receiving the nested folder path.
Key Configuration: Configured to accept an input named folder.
Code (Paths n8n node):
Function: Transforms the single path string into an array, where each item contains the specific folder name, its full relative path, and its immediate parent's relative path, which is crucial for the sequential creation logic.
Datastore (clearParent, setParentFound, setParentCreated, getParent n8n nodes):
Function: Used for state management across loop iterations. The n8n datastore temporarily holds the ID (parentID) of the most recently processed folder, allowing the next iteration to know where to create the subsequent nested folder.
Split In Batches (Loop Over Items n8n node):
Function: Controls the flow, ensuring that the n8n workflow processes one folder segment completely (search, conditional check, creation) before moving to the next segment in the path.
Microsoft OneDrive (Search & Create a folder n8n nodes):
* Function: The primary integration node. The Search operation checks for folder existence, and the Create a folder operation generates the new directory using the parent ID provided from the datastore.

Related n8n Workflows

Free

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

Featured*