Waking Up from the File Organization Nightmare
When running B2B operations, dozens of orders, shipping documents, and contracts flood into Google Drive every single day. Files like 「2024-01-15-Buyer-A-PO.pdf」 and 「Invoice-001-Jan.xlsx」 pile up in chaos. As a non-developer, I used to sacrifice lunch hours each week sorting these files by date and buyer into different folders. It was tedious and error-prone.
One day I realized that combining Claude Code with Google Apps Script could automate this entire process.
How Does It Work?
Read the pattern embedded in filenames and automatically move files to the right folders.
Suppose you have this naming convention:
• 「YYYYMMDD-BuyerName-DocumentType.pdf」
• Example: 「20240115-BuyerA-PO.pdf」
Our automation would detect and organize it like this:
Drive Root
└─ January 2024
└─ BuyerA
└─ PO (Folder)
└─ 20240115-BuyerA-PO.pdf
Step-by-Step Implementation Guide
Step 1: Open Apps Script in Google Drive
1. Go to Google Drive, click 「New」
2. 「More」 → 「Google Apps Script」
3. Name the new project 「FileAutoSorter」
Step 2: Generate Script Code with Claude Code
Ask Claude the following:
「Create a Google Apps Script that reads all files in a specific Google Drive folder, analyzes them based on the YYYYMMDD-BuyerName-DocType naming pattern, and automatically moves them into a year/month/buyer/document-type folder structure. Auto-create missing folders and skip already-moved files.」
Claude will generate code with a structure like this:
function autoSortFiles() {
const sourceFolder = DriveApp.getFolderById(「YOUR_FOLDER_ID」);
const files = sourceFolder.getFiles();
while(files.hasNext()) {
const file = files.next();
const fileName = file.getName();
const pattern = /^(\d{8})-(\w+)-(\w+)\./;
const match = fileName.match(pattern);
if(match) {
const date = match[1];
const buyer = match[2];
const docType = match[3];
const year = date.substring(0, 4);
const month = date.substring(4, 6);
// Folder creation and file movement logic
createAndMoveFile(sourceFolder, file, year, month, buyer, docType);
}
}
}
Step 3: Paste Code and Set Folder ID
1. Copy the generated code into the Apps Script editor
2. Extract folder ID from your target folder URL: 「https://drive.google.com/drive/folders/`1a2b3c4d5e6f`」
3. Replace 「YOUR_FOLDER_ID」 with your actual folder ID
Step 4: First Run, Authorization, and Testing
1. Click the 「Run」 button
2. Google account authentication popup → Grant permissions
3. Test on a small test folder first (5-10 files)
4. Verify files landed in the correct directories
Step 5: Set Up Automated Scheduling (Optional)
To auto-sort at a specific time each day:
1. 「Triggers」 → 「Create new trigger」
2. Function: autoSortFiles, Deployment: Head, Event type: Time-based
3. Select 「Day timer」 → Choose time (e.g., 9 AM)
What Actually Happened
Success: After first deployment, we saved 1.5 hours per week. Human errors (duplicate placements, wrong folder selections) dropped to nearly zero.
Failure: Initially, inconsistent filename conventions caused only 40% match rate. Once the team standardized filenames, we achieved 100% automation.
Surprise: A colleague asked, 「Can I use this too?」 That's when we realized a well-designed script is reusable across departments.
Level Up: Advanced Features
Ask Claude to add:
• Auto-log all file movements to a Google Sheet
• Send email notifications to handlers upon completion
• Isolate rule-violating files to a 「Manual Review」 folder
You can integrate all these into a single script.
Final Thoughts
Repetitive work like file sorting is the perfect entry point for automation. Non-developers can absolutely build this by understanding the pattern and conversing with Claude. Come Monday morning, your Google Drive can be perfectly organized too.