How to create nested folders in Google Drive in bulk automatically

How to create nested folders in Google Drive in bulk automatically

Google Drive makes one of the best tools for storing shared documents. However, setting up the structure of folders in Google Docs can become a tedious task for all new clients and projects. In this guide, we will show you how you can create nested folders in Google Drive in bulk automatically. This means you will be able to create additional folders within the original or first folder, and more. 

A nested folder automation makes one of the most useful additions to the client who is onboarding workflow, a workflow of product launch, or any other situation or event when you will need sets of similarly structured folders. 

Creating nested folders in Google Drive in bulk automatically is quite simple. It makes a suitable decision for almost any skill. All you have to do is follow the below-mentioned step-by-step guide on how to create nested folders in Google Drive in bulk automatically to get started. 

Once you learn how to make nested folders in Google Drive in bulk automatically, setting up new clients, new projects, and more will no longer be a hassle. It will only ensure that all the folders which are created are consistent. So, you won’t have to worry about any disorganized files or folders any longer. 

Creating nested folders in Google Drive in bulk can get cumbersome. What if you are a university or school teacher who needs to create identical folder structures for all your students? This overwhelming task can be simplified by creating a Google Sheet as a pre-requisite to not only define the folder names but also the folder levels. 

In this blog, we will be telling you about the perfect Google Apps Script that all the team managers, project leads, teachers, or anyone desiring to set up Google Drive folders as well as sub-folders can use. This automation is definitely all you need to quickly as well as efficiently create bulk Google Drive folder files and structures. 

The Google Apps Script code below allows you to create folder structures in Google Drive from structures that have been defined in the Google sheets document. Follow the steps as it is for the most hassle-free and seamless creation experience. 

Creating folder structures can be tedious. What if you are a school/university teacher and want to create the same list of folder structures for every student? Let’s simplify this overwhelming task.

As a pre-requisite, you can create a Google sheet to define folder names and level of the folders.

Here is the full code for creating a folder structure in Google Drive from a structure defined in a Google Sheets document, with the ability to define multiple levels of folders using Google Apps Script:

// Get the ID of the sheet
var sheetId = "YOUR_SHEET_ID";

// Get a reference to the sheet
var sheet = SpreadsheetApp.openById(sheetId).getSheets()[0];

// Get the data range for the sheet
var dataRange = sheet.getDataRange();

// Get the values for the data range
var values = dataRange.getValues();

// Create an array to store the folder structure
var folderStructure = [];

// Loop through the values and add the folder names and levels to the folderStructure array
for (var i = 1; i < values.length; i++) {  // Skip the first row (headers)
  var folderName = values[i][0];
  var folderLevel = values[i][1];
  folderStructure.push({name: folderName, level: folderLevel});
}

// Create the folder structure
var rootFolder = DriveApp.getRootFolder();
var currentFolders = {};
for (var i = 0; i < folderStructure.length; i++) {
  var folder = folderStructure[i];
  var folderName = folder.name;
  var folderLevel = folder.level;
  if (folderLevel == 1) {
    // Create a new level 1 folder
    rootFolder = rootFolder.createFolder(folderName);
    currentFolders[folderLevel] = rootFolder;
  } else {
    // Create a new folder at the current level
    var parentFolder = currentFolders[folderLevel - 1];
    var newFolder = parentFolder.createFolder(folderName);
    currentFolders[folderLevel] = newFolder;
  }
}

To use this code, you will need to replace “YOUR_SHEET_ID” with the ID of the sheet that contains the folder structure. You will also need to ensure that the sheet has the correct format, with the folder name in the first column and the folder level in the second column.

This code will read the folder structure from the sheet and create a nested set of folders in Google Drive, starting with the root.