Recently I was tasked with finding a way to create a folder at the press of a button using a Google Spreadsheet.
This was relatively simple with a bit of Apps Script so here’s a simple guide on how to do it.
First create a sheet with the folder name in a cell:
Then add this bit of simple Apps Script:
/**
* ================================= FOLDER =================================
*/
function makeFolder(){
var sheetName = "<YOUR SHEET NAME>"
var parentFolderID = "<YOUR PARENT FOLDER ID>" //This can just be a Shared Drive.
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName(sheetName)
var newFolderName = sheet.getRange("<THE CELL CONTAINING YOUR FOLDER NAME>").getValue()
Logger.log("The new Foider will be called:"+newFolderName)
var parentFolder = DriveApp.getFolderById(parentFolderID)
var newFolderID = parentFolder.createFolder(newFolderName).getId()
Logger.log("The ID of the new folder is "+newFolderID)
}
And then this can be triggered by a button which you can add with this bit of code:
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('Create Folder')
.addItem('Create Folder', 'makeFolder')
.addToUi();
}
Which will create a button that looks like this:
And that’s it!
This is the simplest version that only creates a single folder at a time but you could very easily add a loop to create multiple at once.