Move old Drive files into an Archive folder

Moves files not updated in 180 days from one folder into an "Archive" subfolder.

function archiveOldFiles() {
  const source = DriveApp.getFolderById('PASTE_SOURCE_FOLDER_ID');
  const archives = source.getFoldersByName('Archive');
  const archive = archives.hasNext() ? archives.next() : source.createFolder('Archive');
  const cutoff = new Date(Date.now() - 180 * 24 * 3600 * 1000);
  const files = source.getFiles();
  while (files.hasNext()) {
    const f = files.next();
    if (f.getLastUpdated() < cutoff) f.moveTo(archive);
  }
}

How to install

  1. Open the spreadsheet, then Extensions > Apps Script.
  2. Paste the code, click Save.
  3. Choose the function in the toolbar and click Run once; approve the permissions screen (it lists exactly what the script can touch).
Safety: Test on a copy of the folder first. The folder ID is the long string after /folders/ in the folder URL.

Undo: Files are moved, not deleted; drag them back to undo.

Reference: Apps Script documentation.

Facts on this page checked December 4, 2026 (Pacific) against the linked official sources.