Tuesday 1 October 2019

Create alphabetised folders in Google Drive

The following Google Apps Script is designed to bulk create folders from a Google Sheet and to arrange them into alphabetised folders within Google Drive, by extracting the first letter of their surname.
Screenshot of example Google Sheet data for creating folders
Screenshot of example Google Sheet data for creating folders

If a suitable alphabetised folder does not exist in Google Drive, then one is created. The script also adds the created folder to an 'Everybody' folder so that there is a single area with all the folders listed in.
Screenshot of Google Drive folder layout
Screenshot of Google Drive folder layout

This function gets all of the initial data from the Google Sheet including the parent folder IDs to be used. It then calls the next function to start creating the Google Drive folder for the current row it is on.

We now loop through each row and extract the forename, surname, etc and produce a variable called initial which is the first letter of the surname and will be used to look for a matching folder within Google Drive. This function then calls the next one to see if a folder currently exists which if one does it can create the new folder within it, otherwise it creates a new alphabetised folder.

This function iterates through the parent folder and extracts the names of all sub-folders, then it looks for a match with the previous surname initial and returns the folder ID if one is found. So in effect it is looking through multiple folders titled individual letters of the alphabet to find a match with the surname.

Folders - create alphabetised directory.xlsx

No comments:

Post a Comment