Author: By Raj
Part of our Google Workspace Automation guides. Need this built for your team? Hire a Google Apps Script developer.
Estimated reading time: 10 minutes
Auto-Organize Google Drive Files with Apps Script
Drive file organizers sort uploads from email attachments, form uploads, or shared inbox folders into YYYY/MM/client hierarchies automatically on schedule.
Rules read from OrganizerRules sheet: if MIME contains pdf and name contains Invoice route to Finance/Invoices. First match wins unless priority column sorts rules.
Works with DriveApp iterators; log moves to Moves tab for undo guidance, Drive lacks full undo API.
Inbox folder watcher
Time-driven scan of Inbox folder children. Skip Google Docs shortcuts and already-tagged files with property description ORGANIZED=true if you set custom metadata via API.
Process max 100 files per run.
Rule engine
Load rules array [{mime, nameContains, destFolderId, priority}]. Sort by priority descending.
Default rule catches unmatched to Review/NeedsClassification.
Rename conventions
Prepend ISO date Utilities.formatDate(file.getDateCreated(), tz, 'yyyy-MM-dd') + '_' + originalName for sortability.
Sanitize slashes in names to avoid path confusion.
Shared drive targets
destFolderId must be accessible to script owner. Test moves on sample file before bulk.
Combine with CSV import organizer in /blog/google-sheets-import-csv-automatically.
Example code
function organizeInbox() {
const inbox = DriveApp.getFolderById('INBOX_FOLDER_ID');
const rules = SpreadsheetApp.openById('RULES_SHEET_ID').getSheetByName('Rules').getDataRange().getValues();
rules.shift();
const files = inbox.getFiles();
let n = 0;
while (files.hasNext() && n < 100) {
const file = files.next();
const dest = resolveDestination(file, rules);
if (dest) file.moveTo(DriveApp.getFolderById(dest));
n++;
}
}
function resolveDestination(file, rules) {
const name = file.getName();
const mime = file.getMimeType();
for (var i = 0; i < rules.length; i++) {
if (mime.indexOf(rules[i][0]) >= 0 && name.indexOf(rules[i][1]) >= 0) return rules[i][2];
}
return null;
}| Approach | Best for | Tradeoff |
|---|---|---|
| Apps Script native | Google Workspace-centric workflows | 6-min limit, quotas |
| Zapier / Make | No-code, many connectors | Per-task cost, vendor lock-in |
| Python + Cloud | Heavy data / ML | Hosting cost, separate auth |
| Google Workspace automation | Production custom logic | Build cost, you own code |
FAQ
Can organizer run on form upload folder?
Yes, point inbox folder ID to Form upload destination in Drive settings.
Undo mistaken move?
Log fromId, toFolderId in Moves sheet; manual move back or script undo function reading log.
Shortcuts?
Decide policy, skip shortcuts or resolve target via Advanced Drive API.
Performance on 10k files?
Archive old inbox items quarterly; organizer not meant for full Drive search replacement.
Drive automation basics?
See /blog/apps-script-google-drive-automation for permissions and folder factories.
Need this done for you? I handle this as part of my consulting work, fixed-price quote within 24 hours.
Book a call with Raj →Get the full Auto-Organize Google Drive Files with Apps Script script template
I'll email you a production-ready, commented version you can deploy in 10 minutes.
Continue reading
Gmail, Drive & Workspace
Sync Google Calendar to Sheets: Events and Availability
Gmail, Drive & Workspace
Sync Google Calendar with Microsoft Outlook (Apps Script + Graph)
Gmail, Drive & Workspace
Gmail Automation with Google Apps Script: Filters, Labels & Auto-Reply
From another topic
How to Automate Google Sheets with Apps Script (Beginner Guide) →Need help with this? I handle this as part of my Google Workspace Automation service.
Gmail, Drive, Docs, Forms, and Calendar automation.
See how it works →