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);
}
}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.