This is a simple script that you can use to quickly generate a set of folders that are each individually shared with a student.
First, create a spreadsheet that has the student’s names and email addresses. Our student emails are based off of their student ID numbers. This makes the email address portion very easy to create as I simply use the =CONCATENATE function in the cell next to a student’s ID number. Then I fill down the column to populate the student’s emails.
Now, create a folder that you want to place all the shared folders in. You will need that folder’s ID when you construct the code for this project. The folder’s ID is the last part of the folder’s URL. The blue text in this URL, for example: https://drive.google.com/drive/folders/0B08GtMgrcMSBc002cENGeFhjdTQ
Go back to the spreadsheet with the student’s names and emails and click the Tools menu item and then click the Script editor item.
If prompted, select blank project or create a new project.
Delete the myFunction(){} and paste in the following code.
function createFolders() { var spreadSheet = SpreadsheetApp.getActiveSpreadsheet(); var sheet = spreadSheet.getActiveSheet(); var genericFolder = 'GenericName';//the base name for each folder var parentFolder = DriveApp.getFolderById('ID Number of folder'); //get the parent folder where the subfolders will locate var startRow = 2; // First row of data to process because row 1 is headers var numRows = sheet.getLastRow(); // Number of rows to process var dataRange = sheet.getRange(startRow, 1, numRows, 3); // Fetch the range of the whole spreadsheet var data = dataRange.getValues(); // Fetch values for each row in the Range. for (var i = 0; i < sheet.getLastRow()-1; ++i) { var row = data[i]; var name = row[0]; var email = row[2]; var folderName = parentFolder.createFolder(name + " " + genericFolder); //creates the folder based on your naming convention folderName.addEditor(email);//shares the folder via email address sheet.getRange(startRow + i, 5).setValue(folderName.getId()); //sets the folder ID in the spreadsheet so you can use it later Utilities.sleep(1000); //method to slow down the autocreate bc it crashes } }
Now make a couple of edits. First, change the name of the genericFolder to whatever you want the base name of the folder to be. Next, change the parentFolder to be the ID of the folder you want these folders to be placed in. Finally, if your student’s names are not in the first column, change the number in the var name line to whichever column converted to a number (A=0, B=1, C=2 etc… since you are iterating through an array, it begins counting at 0). Similarly, if the email is not in column C, change the var email number to the appropriate one.
If you didn’t already do so, press the disk icon and save your code. Give it a name like createFolders. Then press the play button. You will have to authorize the code to use some Google functionality. Press play again to run the code and create the folders. The code will also add a column in your spreadsheet that has the folder ID for each folder. If you don’t want or need that, feel free to delete line 18 of the code:
sheet.getRange(startRow + i, 5).setValue(folderName.getId()); //sets the folder ID in the spreadsheet so you can use it later
You must be logged in to post a comment.