Bulk Create Google Drive Folder Structures & Files
Perfect for project managers, team leads, teachers or anyone who needs to set up a set of Google Drive folders and subfolders quickly
This Apps Script is perfect for project managers, team leads, teachers or anyone who needs to set up a set of Google Drive folders and subfolders quickly and efficiently using automation instead of manual clicks.
Kudos to https://www.pbainbridge.co.uk/2020/06/bulk-create-google-drive-folders-20.html and various stackoverflow threads for filling in some gaps about how things work.
Overview:
- Google Sheet stores the names of the folders & subfolders to be created
- Specify the root folder(s) where the new hierarchy will be created
- Specify the viewers or editors that should have access to each folder or subfolder
- Specify documents (sheets, docs, files) that should be pre-loaded into each folder (like an agenda template, project instructions, team roster, etc)
- Trigger the creation via a custom menu in the Google Sheet
Example:
You want to create a structure like this:
Main Folder: My Projects
….SubFolder: Project A
….….Sub-Sub-Folder: Project A Agendas
….….….File: Agenda Template Document
….….Sub-Sub-Folder: Project A Resources
….….…. File: Basic Resources.pdf
….SubFolder: Project B
….….Sub-Sub-Folder: Project B Agendas
….….….File: Agenda Template Document
….….Sub-Sub-Folder: Project B Resources
….….….File: Basic Resources for Project B.pdf
(and you want a different set of viewers/editors for the different folders)
Code
(if you already know what you're doing)
Procedure for the example:
- Copy the Google Sheet so it's owned by you
- Update the Google Sheet so it points to your own base/root folder (the one where all the other subfolders are going to be created)
- Use the examples already in the sheet (Team A etc) so you see how it works before you run it for your own purposes. You can just delete what's created afterwards anyway.
- Click the "Extensions" menu, then click "Apps Script"
- This will open the Apps Script editor.
- Update the variables if you want (you don't need to, but you can)
- With the "onOpen" function listed at the top, click "Run"
- This will popup a window asking for permissions, so you can let Apps Script run on your own account. It's you, granting permissions to your script, to have access to your content. Follow the prompts (even if it says "unsafe") and approve the access. Note, the unsafe part is because this is your code, and it's not an official source vetted and approved already by Google.
- After it runs successfully, close the script editor window and return to the Google Sheet.
- There should be a new menu item called "Neat Features" (if not, refresh the browser and it will show up).
- Click on the "Generate Folders" menu item to create your folders according to what's in the google sheet.
- That's it. Check the folder in google drive to see the new folders and template files that were placed inside them. Check the permissions too if you chose to set the Viewer/Editor stuff as well.
- That's really it.
- Add new rows to the sheet and run it again, and it will continue to work for anything else you add (but only after you click Generate Folders Now).
Hope this helps!
Check out this and other apps script code samples at: https://github.com/usaussie