Recipe
Create a Drive folder for each new row in Google Sheets
For every row that has a name but no link, the script creates a folder inside a parent folder and writes the folder link back into column B.
Set it up
- Make a parent folder in Drive and copy its ID. Paste the script and set parentId in CF.
- Run createFolders and approve the prompts.
- Optional: add a time-driven trigger so new rows get folders on their own.
The script
/**
* Create a Drive folder for each new row and write its link back to the sheet.
* Columns: A Name, B Folder link (filled by the script).
* Add a time-driven trigger (every 10 minutes or hourly) for createFolders.
*/
var CF = { sheetName: 'Sheet1', parentId: 'PASTE_PARENT_FOLDER_ID', linkCol: 2 };
function createFolders() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(CF.sheetName);
var values = sheet.getDataRange().getValues();
var parent = DriveApp.getFolderById(CF.parentId);
var made = 0;
for (var i = 1; i < values.length; i++) {
var name = String(values[i][0]).trim();
if (!name || values[i][CF.linkCol - 1]) continue;
var folder = parent.createFolder(name);
sheet.getRange(i + 1, CF.linkCol).setValue(folder.getUrl());
made++;
}
return made;
}What you should see
| Client | Folder |
|---|---|
| Northwind | drive.google.com/drive/folders/1AbC... |
| Fabrikam |
Links are written to column B. Sample values, not output from a real account.
Common errors and fixes
- Exception: No item with the given ID could be found
- parentId is wrong, or the account cannot see that folder.
- Duplicate folders
- Column B must keep the link. If it is cleared, the next run makes another folder.
- Exceeded maximum execution time
- Run it more often, or process rows in batches.
Permissions. Running this script asks you to grant Google permissions for the services listed above, to your own script. TriggerShelf never receives your Google data. See the permissions table. Google will show "Google hasn't verified this app"; that is expected for a script you paste yourself.
TriggerShelf is independent and not affiliated with or endorsed by Google LLC. Google Sheets, Gmail, Google Drive and Apps Script are trademarks of Google LLC. Quota figures come from Google's Apps Script quotas page. Test on a copy first.