Create Multiple Sub-folders in Google Drive Automatically



Automatically creating multiple sub-folders in Google drive helps organize files efficiently and saves time. Instead of manually setting up folders, using App Script for automatic sub-folders ensures efficient document management. This is important for educators and individuals handling large datasets, as it improves accessibility, collaboration and systematic file management.

Step by step procedure for creating multiple sub-folders in google drive automatically is given below as:-

Step 1: Open Google Drive and create a parent folder

Go to https://drive.google.com/drive.Click New.

And then, select New Folder.

Name the folder (e.g., Main Folder) and click the Create button.


Open the Folder and copy the Folder Id from the UR. It is a long string after folders/, i.e., 1IkFsNJU9C-JvrE8aOurj052j9jUHYq0-

Step 2: Setting in Google App Script

Open Google sheets and create a Blank Spreadsheet.


Click the Extensions tab.


Select Apps Script. The following editor editor will appear -


Step 3: Add the code

After clicking on Apps Script, the editor will appear. Delete all the existing code and paste the following:

function createSubFolders() {
var parentFolder = DriveApp.getFolderById("YOUR_PARENT_FOLDER_ID");
var subFolderNames = ["Folder1", "Folder2", "Folder3"]; // Add folder names

subFolderNames.forEach(function(name) {
parentFolder.createFolder(name);
});

Logger.log("Folders created successfully!");
}

Replace "YOUR_PARENT_FOLDER_ID" with the actual Folders id.

Access the code from https://bit.ly/42mzN42

Step 4: Save and Run the Script

Click the Save button.


Then, execute the code by clicking Run.


Step 5: Authorize the Script

Authorize the script as follows:

Click Review permissions.


Sign in with the same Gmail account linked to your Google Sheet and Google Drive.


Click  Advanced.


Click on Go to Untitled project (unsafe).


Finally, click the Continue button.



Step 6: Verify the execution log

You will get to see the following message after the script ran successfully.

Step 7: Your Automatic file generation process is ready


To create sub-Folders again, simply click Run.

Updated on: 2025-04-14T12:07:21+05:30

32 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements