๐ Create Google Drive folders by path
โก 1,907 views ยท ๐ File Management
Description
This workflow creates nested Google Drive folders from a path string (like Projects/Clients/Reports). It automatically handles the necessary folder lookups and creation steps required by Google Drive, then outputs the final folderโs ID for immediate use.
How it works
This workflow streamlines the creation of nested folders in Google Drive:
- Input: Provide a
root_folder_idand a path (e.g.,Projects/Clients/Reports) as input. - Path Parsing: The workflow splits the path into individual folder names (based on the
/separator) - Iterative Check & Create: Loops through each part of your path:
- Searches within the current parent folder (starting with the
root_folder_id) for a subfolder matching the name. - If found: Retrieves the existing folderโs ID to use as the parent for the next iteration.
- If not found: Creates a new folder with that name inside the current parent folder and uses the new folderโs ID as the parent for the next iteration.
- Searches within the current parent folder (starting with the
- Output: Returns the Google Drive Folder ID of the very last folder in the specified path (e.g., the ID for
Reportsin the example above). This ID can then be directly used in subsequent n8n nodes to upload files, create documents, or perform other actions within that specific folder.
Set up steps
Setting up this workflow requires configuring the connection to Google Drive and knowing where to start creating folders:
- Connect Google Drive Account: Ensure you have a Google Drive credential configured in your n8n instance. Then link your credentials in the workflow: there are 2 Google Drive nodes that will need to be updated.
- Identify Starting Folder ID: Determine the Google Drive Folder ID where your nested structure should begin. You can either use the root of your Google Drive or a specific folder:
- To use the root of Google Drive, simply set
root_folder_idtoroot(also called โMy Driveโ in the UI) - To use a specific folder, open the folder in a webbrowser and look at the URL. The folder ID will be in the last part of the URL:
https://drive.google.com/drive/folders/THIS_IS_THE_FOLDER_ID.
- To use the root of Google Drive, simply set
- Prepare Inputs for Execution: When running the workflow (or triggering it), you will need to provide:
google_drive_folder_id-> this is the root folder ID you identified in step 2.desired_path-> This is the path you want to create (e.g.,Projects/Clients/Reports).
Hereโs an example of how you can call this workflow in your other workflows:
image.png
image.png
๐ Nodes Used
Google Drive, Execute Workflow Trigger
๐ฅ Import
Download workflow.json and import into n8n:
Workflow menu โ Import from File