Apps Script – Automatically Create Folder Structures in Google Drive Based on Sheet Data (Google Sheet)

Ever wished you could automatically organize your Google Drive based on your spreadsheet data? With Google Apps Script, you can do exactly that. Imagine typing a list of folder names in a Google Sheet and instantly generating a full folder structure inside your Drive — all with a single click.

This is a fantastic trick for beginners who use Google Sheets to manage projects, students, clients, or events. Instead of manually creating dozens (or hundreds) of folders, let your spreadsheet do the heavy lifting.

In this guide, you’ll learn how to build a script that reads folder names from your Sheet and creates them automatically in Google Drive — neat, fast, and fully customizable.

Apps Script - Automatically Create Folder Structures in Google Drive Based on Sheet Data (Google Sheet)

Real-Life Scenario: School Year Class Folder Setup

Let’s say you’re a school administrator preparing folders for different classes each year. Instead of manually creating folders for every class, section, and subject, you enter them into a Google Sheet like this:

Sample Sheet Data

Grade Section Subject
Grade 6 A Math
Grade 6 A Science
Grade 6 B English
Grade 7 A Math

You want folders like this created in your Drive:

  • Grade 6
    • A
      • Math
      • Science
    • B
      • English
  • Grade 7
    • A
      • Math

Step-by-Step: Create Folder Structures from Sheet

Step 1: Set Up Your Google Sheet

  • Create a new sheet and name it Class Folders
  • Input your data in the format shown above (Grade, Section, Subject)

Step 2: Open the Script Editor

  1. Go to Extensions → Apps Script
  2. Delete any existing code in Code.gs

Step 3: Paste the Folder-Creation Script


function createFoldersFromSheet() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Class Folders");
  const data = sheet.getDataRange().getValues();
  const parentFolder = DriveApp.createFolder("📁 School Folders " + new Date().getFullYear());

  for (let i = 1; i < data.length; i++) {
    const grade = data[i][0];
    const section = data[i][1];
    const subject = data[i][2];

    let gradeFolder = getOrCreateFolder(parentFolder, grade);
    let sectionFolder = getOrCreateFolder(gradeFolder, section);
    getOrCreateFolder(sectionFolder, subject);
  }

  SpreadsheetApp.getUi().alert("Folders created successfully in your Drive!");
}

function getOrCreateFolder(parent, name) {
  const folders = parent.getFoldersByName(name);
  return folders.hasNext() ? folders.next() : parent.createFolder(name);
}

Step 4: Run the Script

  • Click the play ▶️ button next to createFoldersFromSheet
  • Authorize the script when prompted
  • Once it runs, check your Google Drive — the folders will be there!

Key Benefits

  • Mass Automation: Create hundreds of folders in seconds
  • Zero Manual Errors: Avoid typos or missing folders
  • Organized Hierarchy: Folders are structured by parent-child logic

Pro Tips

  • You can modify the script to add subfolders like “Assignments” or “Notes” inside each subject
  • Add timestamp logs in another sheet to keep track of what was created
  • Want to reuse an existing folder instead of creating a new one? Use DriveApp.getFolderById() with your Drive folder ID

Quick-Reference Cheat Sheet

Function / Term Meaning
DriveApp.createFolder(name) Creates a new folder in Google Drive
getFoldersByName(name) Searches for existing folders with the specified name
SpreadsheetApp.getActiveSpreadsheet() Accesses the current spreadsheet
alert() Shows a popup message in the spreadsheet UI

Creating folder structures manually is a boring and error-prone task. But with the help of a Google Sheet and a bit of Apps Script, you can automate this entire process with just one click. Whether you’re organizing school years, client projects, employee documents, or event folders — this trick will save you time and keep everything tidy.

Give it a try, tweak it to your needs, and watch your Google Drive organize itself!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top