Auto-archive finalized Docs to dated folders
File completed Northwind Docs by month so the active folder stays focused on in-flight work.
Published Jan 18, 2026
Northwind keeps in-progress Docs in a single active folder, and it slowly turns into a junk drawer. Finished work sits next to live drafts, and finding the thing you are actually working on means scrolling past months of completed proposals and reports.
This script keeps the active folder lean. On a schedule it scans for any Doc
whose name is tagged [final], then moves it into a dated archive folder for
the current month — creating that folder if it does not exist yet. Finished
work is filed away by month; the active folder shows only what is still in
progress.
What you’ll need
- An active Drive folder where in-progress Docs live.
- An archive root Drive folder where dated sub-folders will be created.
- A naming convention: when a Doc is done, add
[final]somewhere in its name (the match is case-insensitive). That tag is the only signal the script uses. - The IDs of both folders, taken from their URLs.
The script
// Folder where in-progress Docs live and get scanned.
const ACTIVE = '1abcActiveDocsFolderId';
// Parent folder under which monthly archive sub-folders are created.
const ARCHIVE_ROOT = '1abcArchiveRootId';
// A Doc is archived when its name contains this tag (case-insensitive).
const FINAL_TAG = '[final]';
/**
* Moves every finalised Doc out of the active folder and into a
* year-month sub-folder under the archive root.
*/
function archiveFinalisedDocs() {
const files = DriveApp.getFolderById(ACTIVE).getFiles();
let moved = 0;
// Walk every file in the active folder.
while (files.hasNext()) {
const file = files.next();
// Skip anything not tagged as final — leave drafts in place.
if (!file.getName().toLowerCase().includes(FINAL_TAG)) continue;
// Find or create this month's archive folder, e.g. "2026-01".
const monthName = Utilities.formatDate(new Date(), 'GMT', 'yyyy-MM');
const monthFolder = getOrCreate(DriveApp.getFolderById(ARCHIVE_ROOT), monthName);
// Move the finished Doc into the dated folder.
file.moveTo(monthFolder);
moved++;
}
Logger.log('Archived ' + moved + ' finalised Doc(s).');
}
/**
* Returns the named sub-folder of `parent`, creating it if it does not
* already exist.
*/
function getOrCreate(parent, name) {
const it = parent.getFoldersByName(name);
return it.hasNext() ? it.next() : parent.createFolder(name);
}
How it works
archiveFinalisedDocsopens the active folder and gets an iterator over every file inside it.- For each file it checks the name, lower-cased, for the
[final]tag. Anything without the tag is skipped, so live drafts stay put. - For a tagged Doc it builds the current month’s folder name with
Utilities.formatDate—yyyy-MM, so January 2026 becomes2026-01. getOrCreatelooks for a sub-folder of that name under the archive root. If one exists it reuses it; if not it creates it. The first finalised Doc of the month makes the folder, and the rest drop into the same one.file.moveTorelocates the Doc into the dated folder. In Drive a file has one set of parents, so this removes it from the active folder in the same step.
Example run
Suppose the active folder holds these four Docs when the script runs in January 2026:
| Doc name | Tagged final? | Result |
|---|---|---|
| Q1 proposal — Harbour Co [final] | yes | moved to 2026-01 |
| Service overview draft | no | stays in active folder |
| Case study — Lumen Ltd [FINAL] | yes | moved to 2026-01 |
| Onboarding guide v3 | no | stays in active folder |
After the run, the archive root contains a 2026-01 folder with the two
finished Docs, and the active folder is down to the two live drafts.
Trigger it
Run this once a day so finished Docs file themselves away:
- In the Apps Script editor, open Triggers (the clock icon).
- Click Add Trigger.
- Choose
archiveFinalisedDocs, event source Time-driven, type Day timer, and set a quiet hour such as 3am to 4am. - Save, and approve the Drive authorisation prompt on the first run.
Watch out for
- The Doc is filed by the date the script runs, not the date the work
finished. Tag a Doc
[final]in late January but let the run slip to February, and it lands in2026-02. Run daily to keep this tight. - The match is a plain substring check. Any Doc with
[final]in its name is archived — including a draft sloppily namednear-final notes. Keep the tag distinctive. formatDateuses theGMTtimezone here. Near midnight that can put a Doc in the previous or next day’s month. SwapGMTfor your own timezone string if that matters.getFiles()returns every file type in the folder, not just Docs. A Sheet or PDF named with[final]would also be moved — narrow it withgetFilesByType(MimeType.GOOGLE_DOCS)if the folder is mixed.- Moving a Doc does not change its sharing. Anyone with a direct link still reaches it; only people who browsed to it via the active folder lose the path.
Related
Generate personalized study guides from notes
Reformat raw notes into structured study guides — for Northwind's internal training programme.
Updated Feb 8, 2026
Build a contract-clause assembly system
Construct Northwind agreements from a library of approved clauses — drag-drop in code.
Updated Feb 1, 2026
Translate and resolve Doc comments
Localise reviewer feedback on a shared Doc so multilingual teams can collaborate.
Updated Jan 25, 2026
Build a fillable intake form inside a Doc
Create structured intake forms with placeholder fields readers can fill — for client briefs.
Updated Jan 11, 2026
Generate a printable employee handbook
Compile policy sections into one formatted Northwind handbook Doc.
Updated Jan 4, 2026