Organise Google Drive Files by Type Using Apps Script

Effortlessly streamline your Google Drive organization by using a script to sort files into designated folders.

Organising Google Drive Files by Type with Apps Script

TL;DR:

  • Use Google Apps Script to automatically sort files into folders based on their file type
  • Script checks file extensions (PDF, JPEG, DOCX etc.) and moves them to appropriate subfolders
  • Set up once and let it run automatically whenever new files are added
  • Perfect for anyone dealing with loads of mixed file types in Drive
  • No more manual dragging and dropping files around

Google Apps Script makes it dead simple to organise your Google Drive files by type. Instead of manually sorting through PDFs, images, and documents, you can write a script that does the heavy lifting for you.

How the Script Works

The script scans through your chosen folder, checks each file's extension, then moves files into the right subfolder. A PDF goes to the PDFs folder, a JPEG heads to Images, and so on.

You'll need to define which file types go where. Common groupings include:

  • Documents: .doc, .docx, .txt, .rtf
  • PDFs: .pdf
  • Images: .jpg, .jpeg, .png, .gif, .bmp
  • Spreadsheets: .xls, .xlsx, .csv
  • Presentations: .ppt, .pptx

Setting Up Your File Sorting Script

Create Your Script
Head to script.google.com and create a new project. Give it a name like "File Organiser" so you remember what it does.

Write the Code
You'll need a script that identifies the parent folder containing your mixed files, checks each file's extension, then moves files to their designated subfolders. The script should create subfolders if they don't already exist.

Test Before You Deploy
Run the script on a small test folder first. Check that files end up in the right places and nothing gets lost. Debug any issues with file detection or folder creation.

Set Up Automation
Once you're happy with how it works, you can set triggers so the script runs automatically. You might want it to run daily or weekly, depending on how often you add new files.

Common Gotchas

Files sometimes don't have clear extensions, especially if they've been renamed or come from unusual sources. Your script needs to handle these edge cases gracefully.

Google Drive has rate limits, so if you're processing thousands of files, you might need to add delays or batch the operations.

Shared files and files you don't own might not move properly due to permission restrictions.

FAQs

Can I undo what the script does if it goes wrong?
Moving files back manually is your main option, though you could write a reverse script if you kept track of the original locations. This is why testing thoroughly matters.

What happens to files without extensions?
Your script should account for this. You might create an "Unknown" folder for files that don't match any of your defined types.

Will this work with files shared with me?
Only if you have edit permissions. Files that others own and have shared as view-only won't move.

How do I handle duplicate file names?
Google Drive allows files with the same name in different folders, but your script should check for this and handle it appropriately, perhaps by adding numbers to duplicate names.

Jargon Buster

Google Apps Script – Google's JavaScript-based platform for automating tasks across Google services like Drive, Sheets, and Gmail

File Extension – The bit after the dot in a filename that tells you what type of file it is (.pdf, .jpg, .docx)

Trigger – An automated event that runs your script, like a timer that fires every day or when files are added to a folder

Wrap-up

Automated file sorting saves you from the mind-numbing task of manually organising your Drive. Set it up once, test it properly, and let it handle the boring stuff while you focus on actual work.

The key is starting simple with common file types, then expanding your script as you discover what works for your specific needs. Don't try to handle every edge case from day one.

Ready to automate your workflow? Join Pixelhaze Academy for more hands-on automation tutorials.

Related Posts

Table of Contents