ServicesProductsDocsBlogConsultingAboutContactBook a free call
Back to BlogA studio manager in an architecture firm's archive room sliding a finished client box file into a steel drawer, a hook of returned keys on the wall beside her.
11 min readMageSheet Team

Google Drive Automation: Folders & Sharing

Google Apps ScriptGoogle DriveGoogle WorkspaceAutomationReplace SaaS

Google Drive automation with Apps Script means a new client row in your sheet turns into a complete folder tree, shared with the right people, named consistently, and archived when the work ends, without anyone clicking through Drive. The building blocks are free on any Google account: createFolder() for the structure, permission calls for sharing, the Drive API's expirationTime for access that ends on its own (up to one year ahead), and a nightly trigger for archiving. On a small business's volume, none of it comes close to Google's quotas.

What makes it worth doing isn't the time saved creating folders. It's what happens without it: client files in someone's personal My Drive, a contractor who still has edit access a year after the project ended, three folders called "Acme - FINAL". This post covers the four jobs that fix that, the shared drive caveats that catch people out, and the real limits.

The pipeline in one table

JobTriggerApps Script piece
Create the client folder treeNew row in a Clients sheet, or a form submissionFolder.createFolder(), ID written back to the sheet
Share with the team and the clientSame run, from columns in the sheetaddEditor() / addViewer(), or the advanced Drive service for expiring access
Name files consistentlyWhen the script creates or files a documentOne fileName() helper used everywhere
Remove access and archiveStatus changes to "Closed", checked nightlyremoveEditor() / removeViewer(), then moveTo() an archive folder

The sheet is the control panel. Each client row holds the client name, a status, the people who should have access, and the folder ID once the script has made it. Anyone on the team can see at a glance which clients have folders and who can open them.

Folder structure per client

Agree the template first. Most service businesses we work with settle on four to six subfolders, the same for every client:

const ROOT_ID = 'PASTE_CLIENTS_ROOT_FOLDER_ID';
const SUBFOLDERS = ['01 Contracts', '02 Invoices', '03 Deliverables', '04 From client', '99 Internal'];

function createClientFolders() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('Clients');
  const rows = sheet.getDataRange().getValues();      // A: name, B: status, C: folder ID
  const root = DriveApp.getFolderById(ROOT_ID);
  for (let i = 1; i < rows.length; i++) {
    const [name, status, folderId] = rows[i];
    if (!name || folderId || status === 'Closed') continue;   // already done or not needed
    const client = root.createFolder(String(name).trim());
    SUBFOLDERS.forEach(sub => client.createFolder(sub));
    sheet.getRange(i + 1, 3).setValue(client.getId());
    SpreadsheetApp.flush();                            // record the ID before the next row
  }
}

This uses the built-in DriveApp, which is the simple route for folders in My Drive. If the client root lives in a shared drive, read the shared drives section below first.

Two details make this safe to run over and over:

  • The folder ID is the source of truth, not the name. Drive happily lets two folders share a name, so getFoldersByName('Acme') can return two results and the script will pick one. Storing the ID in column C means the script never creates a folder twice and later steps always find the right one.
  • It skips rows it has already handled. Run it on a 15-minute trigger or from an "on form submit" trigger. Either way, re-running it changes nothing for existing clients.

Numbered prefixes (01, 02, 99) keep the subfolders in the same order in every client folder, which matters more to the team than it sounds. Everyone knows invoices are always second.

Permissions and expiring access

Sharing is where Drive gets messy, because it's done one click at a time and never undone. Driving it from the sheet fixes both. Add columns for team editors and client viewers, and let the script apply them:

function shareClientFolder(folderId, editors, viewers) {
  const folder = DriveApp.getFolderById(folderId);
  editors.forEach(e => folder.addEditor(e));
  viewers.forEach(v => folder.addViewer(v));
}

For a client or contractor who should lose access on a date, use the Drive API's expirationTime, available in Apps Script through the advanced Drive service (enable "Drive API" under Services in the editor). Google's sample shows the same call with sendNotificationEmail: false when you'd rather not have Google email the person:

function grantTemporaryAccess(fileId, email, untilDate) {
  Drive.Permissions.create(
    { role: 'reader', type: 'user', emailAddress: email,
      expirationTime: untilDate.toISOString() },
    fileId,
    { sendNotificationEmail: false, supportsAllDrives: true }
  );
}

The rules from Google's sharing documentation are strict, and they decide how you design this:

RuleWhat it means in practice
Expiry works only on user and group permissions"Anyone with the link" and domain-wide shares can't expire. Avoid them for client work
The date must be in the future, at most one year aheadLong engagements need a renewal step, which the sheet can schedule
On folders, expiring access only works with the reader roleA contractor who must edit a folder needs a different approach

For that last case, and for anything the API won't expire, a nightly job does it: read rows whose end date has passed, call removeEditor() / removeViewer(), and write "access removed" plus the date into the row. That log is also your answer when a client asks who could see their files.

Restricting external sharing is a separate, stronger layer. On Google Workspace, an admin can switch off sharing outside the organisation or limit it to trusted domains, per organisational unit or group, with changes taking up to 24 hours to apply. Set that policy first; scripts work inside it and can't override it. When someone leaves the team, their access should go in the same run that suspends them, which our guide to automating Google Workspace onboarding and offboarding covers in full.

If clients need to see their documents rather than browse a Drive folder, a portal is often cleaner than sharing at all: they log in and see only their own files, and nothing in Drive is shared with them directly. Our guide to building a secure client portal with Apps Script walks through that pattern.

File naming and archiving

Searching a well-named Drive is fast. Searching a badly named one is impossible. Put naming in one function and use it every time the script creates or files something:

function fileName(client, type, date) {
  const d = Utilities.formatDate(date, Session.getScriptTimeZone(), 'yyyy-MM-dd');
  return [d, client, type].join(' - ');            // 2026-11-24 - Acme Ltd - Invoice 0142
}
ConventionWhy
Date first, as yyyy-MM-ddSorting by name sorts by date
Client name exactly as in the sheetOne spelling, so search finds everything
Document type and number last"Invoice 0142" is what people actually search for
No "final", "v2", "new"Drive keeps version history. Use it instead of the file name

For archiving, don't delete. When a client's status changes to "Closed", the nightly job removes outside access, moves the folder into an Archive/2026 folder with folder.moveTo(archiveFolder), and writes the date into the sheet. Files keep their IDs, so every link in your invoices and emails still works for the people who still have access. Deleting is a decision for your retention policy, not for a script.

Shared drives: what changes

For a business on Google Workspace, client work usually belongs in a shared drive rather than one person's My Drive. Files in a shared drive belong to the organisation, so they don't disappear when the person who created them leaves. That alone justifies the move. Three things change for your scripts.

1. Use the advanced Drive service. Google's Apps Script documentation is explicit: to access files or folders in shared drives, use the advanced Drive service rather than the built-in DriveApp. It calls the Drive API (v3 is the default version when you enable it), so you pass supportsAllDrives: true on requests:

function createFolderInSharedDrive(name, parentId) {
  return Drive.Files.create(
    { name: name, mimeType: 'application/vnd.google-apps.folder', parents: [parentId] },
    null,
    { supportsAllDrives: true }
  ).id;
}

2. Sharing rights are different. In a shared drive, files can be shared by organizers, file organizers and writers. Folders can only be shared by organizers by default. If your script runs as a regular team member and tries to share a folder, expect it to fail unless the drive's settings allow file organizers to share folders. The simple fix is to run it from an account with the organizer role on that shared drive.

3. The limits are per drive. From Google's admin documentation:

Shared drive limitValue
Items per shared drive (files, folders, shortcuts and trashed items)500,000
Nested folder levels100
Members per shared drive600, of which at most 100 can be groups
Groups a single file can be shared with directly100

A small agency won't reach 500,000 items in one drive, but a business that scans every delivery note eventually might. Google itself recommends spreading content across several shared drives rather than piling it into one. A shared drive per year, or per department, keeps you well clear.

Quotas and limits

The ceilings that matter for Drive automation, from Google's Apps Script quotas page and Drive API limits page:

LimitPersonal GmailGoogle Workspace
Apps Script runtime per execution6 minutes6 minutes
Total trigger runtime per day90 minutes6 hours
Triggers per user per script2020
Google Docs created per day2501,500
Google Sheets created per day2503,200
Drive API, per user per project325,000 quota units per minute325,000 quota units per minute
Upload and copy into DriveNot stated for personal accounts750 GB per user per day (My Drive and shared drives combined)

What this means in practice:

  • Folder creation and sharing are nowhere near the limits for a business adding a few clients a week. The 6-minute run limit is the one that bites, and only on backfills: creating folders for 800 existing clients in one go. Process a batch per run and save your progress, as in our guide to the Apps Script 6-minute limit.
  • Document creation has a daily cap. If each new client also gets a contract and a tracker generated from templates, count those against the Docs and Sheets limits, especially on a free Gmail account at 250 a day.
  • The Drive API is free for standard use. Google's limits page says the usage limits were updated on 1 May 2026, and that requests above quota are planned to incur charges to the Google Cloud billing account later in 2026, with full details and at least 90 days' notice still to come. A normal folder-and-sharing workload stays far inside the quota, but check that page before you plan a high-volume integration.
  • Quotas can change without notice. Google says so on the quotas page. Build in retries and an alert, and don't design right up to a ceiling.

When a paid tool is the better call

Apps Script handles structure, sharing and housekeeping well. It's not a document management system. If you need legally defensible retention and e-discovery, data loss prevention rules that scan file contents, or a polished client-facing file room with branding and audit reports for regulators, look at Google Workspace's higher editions or a dedicated tool first. For everything else, the folder tree, the sharing rules, the naming and the archive, a script on the account you already pay for does the job without another monthly subscription. We weigh up those trade-offs across other tools in how to replace expensive SaaS with Google Workspace.

If you'd rather have it built than build it, this is a typical fixed-scope Apps Script automation project: the folder template, the sharing rules, the nightly archive job and an alert when something fails, scoped and quoted in writing first.

Want your Drive to run itself?

If client folders are created by hand, shared by whoever remembers, and never cleaned up, a short look at your current setup will tell us what's worth automating and what just needs a rule.

  • Book a free 30-minute discovery call. Show us how a new client gets a folder today and who ends up with access. We'll tell you what the script should do first, and whether a shared drive is the right home.
  • Message us on WhatsApp with roughly how many clients you add a month and who needs access. We'll reply with the folder and sharing setup we'd suggest.

Frequently Asked Questions

Can Apps Script automatically create folders in Google Drive?

Yes. Folder.createFolder(name) creates a subfolder inside any folder the script can edit, so a script can build a full folder tree, such as Client / Contracts, Invoices, Deliverables, from a template list in seconds. The usual trigger is a new row in a client sheet or a form submission. The important detail is to store the new folder's ID back in the sheet, because Drive allows duplicate folder names and searching by name will eventually find the wrong one.

Can I stop files from being shared outside our company?

On Google Workspace, an admin can turn external sharing off, or limit it to a list of trusted domains, for the whole organisation or for specific organisational units or groups. Changes can take up to 24 hours to apply. A script can't override those admin settings, which is the point: use the admin policy as the hard rule, and use Apps Script for the day-to-day work of granting, reviewing and removing access inside that rule. Personal Gmail accounts have no admin layer, so there a script audit is the only control.

Does Apps Script work with shared drives?

Yes, but through the right service. Google's documentation says to use the advanced Drive service, not the built-in DriveApp, to access files or folders in shared drives. The advanced service calls the Drive API v3, where you pass supportsAllDrives: true. Shared drives also change who can share: for files, organizers, file organizers and writers can share; for folders, only organizers can by default.

What is the daily quota for Google Drive automation?

Apps Script itself caps each run at 6 minutes and total trigger runtime at 90 minutes a day on a personal Gmail account or 6 hours on Workspace. If your automation creates new Google Docs or Sheets, those have their own daily caps: 250 a day each on Gmail, and 1,500 Docs or 3,200 Sheets on Workspace. The Drive API allows 325,000 quota units per minute per user per project, and Google Workspace users can upload and copy up to 750 GB a day. Folder creation and sharing for a small business never comes near these.

Can Google Drive access expire automatically?

Yes, for people and groups. The Drive API's expirationTime field sets an end date on a user or group permission, up to one year ahead. It can't be set on 'anyone with the link' or domain-wide sharing, and on folders it only works for viewer (reader) access. For editors on a folder, or link sharing, a scheduled Apps Script job that removes access on the end date covers the gap.

Stay Updated

Get the latest insights on AI, e-commerce, and Magento delivered to your inbox.

We value your privacy

We use essential cookies to make our site work. With your consent, we may also use non-essential cookies to improve user experience and analyze website traffic. By clicking "Accept", you agree to our website's cookie use as described in our Cookie Policy.