Categories We Write About

Archive Google Drive files older than X days

Archiving Google Drive files older than a specified number of days can help you stay organized, reduce clutter, and improve overall productivity. Google Drive does not have a built-in archiving feature with automatic file management by date, but with a combination of manual steps and Google Apps Script, you can automate this task effectively.


Why Archive Old Files in Google Drive?

As digital storage expands, so does digital clutter. Many users store hundreds or even thousands of files over time, and a significant portion of these may no longer be actively needed. Archiving files that haven’t been accessed or modified in X number of days helps:

  • Maintain a clean and efficient workspace

  • Improve search performance within Google Drive

  • Reduce cognitive overload when browsing folders

  • Prepare for compliance and backup needs

  • Prevent accidental deletions of important but dormant files


How Google Drive Handles File Metadata

To automate archiving, it’s essential to understand the metadata Google Drive tracks:

  • Last modified date: When the file was last edited

  • Last viewed date: When someone last accessed the file

  • Created date: When the file was first uploaded or created

The modifiedDate is the most commonly used property when filtering files for automation.


Manual Archiving Workflow

Before diving into automation, here’s a simple manual method:

  1. Sort Files by Last Modified Date

    • Open Google Drive

    • Switch to List View

    • Click on the column header “Last modified” to sort files

  2. Select Files Older Than X Days

    • Manually identify files that are older than your threshold (e.g., 90 days)

  3. Create an Archive Folder

    • Create a folder named “Archive – [Month-Year]”

  4. Move Files

    • Drag and drop selected files into the archive folder

While effective, this process can be time-consuming and subjective. Automating the task provides consistency and saves time.


Automating with Google Apps Script

You can create a Google Apps Script to move files older than X days into an archive folder. Here’s a step-by-step guide:

Step 1: Create the Archive Folder

  1. Go to your Google Drive

  2. Create a new folder named Archive

Step 2: Write the Google Apps Script

  1. Visit https://script.google.com

  2. Click New project

  3. Paste the following script:

javascript
function archiveOldFiles() { const ARCHIVE_FOLDER_NAME = 'Archive'; const DAYS_OLD = 90; // Change this number as needed const archiveFolder = getOrCreateFolder(ARCHIVE_FOLDER_NAME); const cutoffDate = new Date(); cutoffDate.setDate(cutoffDate.getDate() - DAYS_OLD); const files = DriveApp.getRootFolder().getFiles(); while (files.hasNext()) { const file = files.next(); const lastUpdated = file.getLastUpdated(); if (lastUpdated < cutoffDate) { archiveFolder.addFile(file); DriveApp.getRootFolder().removeFile(file); Logger.log(`Archived: ${file.getName()} (Last updated: ${lastUpdated})`); } } } function getOrCreateFolder(name) { const folders = DriveApp.getFoldersByName(name); return folders.hasNext() ? folders.next() : DriveApp.createFolder(name); }

Step 3: Run and Authorize the Script

  1. Click the play (▶️) button beside archiveOldFiles()

  2. Authorize the script with your Google account

  3. It will now move all files older than X days into the Archive folder

Optional: Schedule the Script

To run this automatically:

  1. Click on the clock icon in Apps Script (Triggers)

  2. Add a new trigger for archiveOldFiles

  3. Choose a frequency (e.g., daily, weekly)


Filtering Files from Specific Folders

To only archive files from a certain folder:

Replace this line:

javascript
const files = DriveApp.getRootFolder().getFiles();

With:

javascript
const sourceFolder = DriveApp.getFolderById('FOLDER_ID_HERE'); const files = sourceFolder.getFiles();

To get the Folder ID:

  • Open the folder in Drive

  • Copy the alphanumeric ID from the URL


Use Google Workspace Admin Tools (For Organizations)

If you’re a Google Workspace admin, you can use Google Vault or third-party tools like:

  • SysCloud

  • Spinbackup

  • Afi.ai

These platforms offer automatic backup and archiving of Google Drive content with policy-based automation, including aging policies.


Using Third-Party Automation Tools

Zapier + Google Drive

You can create a Zap that:

  1. Triggers on file updates

  2. Checks the age of the file

  3. Moves or copies it to an archive folder

Make (formerly Integromat)

Similar to Zapier but offers more complex scenarios. You can:

  • Search for files older than X days

  • Move them to a new folder

  • Notify users via email


Best Practices for Archiving

  • Use Naming Conventions: Tag folders or files by month/year for easy tracking.

  • Backup Before Archiving: Always maintain a backup, especially if the archive will be moved to external storage.

  • Regular Reviews: Schedule reviews of archived content to ensure relevance.

  • Access Controls: Limit edit/delete permissions on archived folders.


Limitations and Considerations

  • Google Apps Script quotas may limit the number of files processed in one run

  • Scripts do not detect shared drive files unless explicitly coded

  • DriveApp can’t access file view history — only the last modified timestamp

  • Large numbers of files may slow down script execution; paginate when necessary


Conclusion

Archiving Google Drive files older than X days is essential for maintaining a tidy and manageable digital workspace. While Google Drive doesn’t offer native time-based archiving, using Google Apps Script or third-party automation tools can bridge this gap effectively. By implementing automated archiving workflows, you ensure your Drive remains clutter-free, organized, and efficient over time.

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About