Generate a shareable file-index Doc
List every file in a Northwind folder with links — share one Doc instead of folder access.
Publié le 12 juil. 2025
When a Northwind client asks for “all the project files”, the quick option is to share the whole folder. But that hands them edit history, sub-folders they were never meant to see, and a live view that keeps changing under them. Often what they actually want is a tidy list of what exists and a link to each item.
This script reads one folder and builds a Google Doc that lists every file as a clickable link. You share the Doc, not the folder, so the recipient gets a clean snapshot with no extra access. Re-run it whenever the folder contents change and you have a fresh index in seconds.
What you’ll need
- The ID of the folder you want to index — the string after
/folders/in its URL. - A title for the Doc, so each index is easy to recognise later.
- Edit access to the folder. The script reads file names and URLs only; it never changes the files themselves.
The script
// The folder to index and the title for the generated Doc.
const INDEX_FOLDER_ID = '1abcFolderId';
const INDEX_DOC_TITLE = 'Northwind project files';
/**
* Builds a Google Doc listing every file in a folder as a clickable link.
* Returns the URL of the Doc so you can share it straight away.
*/
function buildFileIndex() {
// 1. Resolve the folder. Bail out early if the ID is wrong.
let folder;
try {
folder = DriveApp.getFolderById(INDEX_FOLDER_ID);
} catch (err) {
Logger.log('Could not open the folder — check INDEX_FOLDER_ID.');
return;
}
// 2. Create the Doc and give it a title heading.
const doc = DocumentApp.create(INDEX_DOC_TITLE);
const body = doc.getBody();
body.appendParagraph(INDEX_DOC_TITLE)
.setHeading(DocumentApp.ParagraphHeading.TITLE);
// 3. Walk the folder and append one linked line per file.
const files = folder.getFiles();
let count = 0;
while (files.hasNext()) {
const file = files.next();
const para = body.appendParagraph('');
para.appendText(file.getName()).setLinkUrl(file.getUrl());
count++;
}
// 4. Note an empty folder so the Doc is never a confusing blank page.
if (count === 0) {
body.appendParagraph('(This folder contains no files.)');
}
// 5. Save and hand back the URL.
doc.saveAndClose();
Logger.log(`Indexed ${count} file(s): ${doc.getUrl()}`);
return doc.getUrl();
}
How it works
buildFileIndexresolvesINDEX_FOLDER_IDinside atry/catch, so a wrong ID produces a clear log message instead of a stack trace.- It creates a new Doc named after
INDEX_DOC_TITLEand adds a matching title paragraph at the top. - It calls
getFiles()and loops through the result. For each file it appends an empty paragraph, then adds the file name as text and attaches the file’s URL as a link withsetLinkUrl. - It counts the files as it goes. If the folder turns out to be empty, it appends a short note so the shared Doc never looks broken.
- It saves the Doc and logs the file count alongside the URL, ready to share.
Example run
Suppose the folder contains three files:
| File in Drive |
|---|
2025 Statement of Work.pdf |
Brand assets.zip |
Kick-off notes.gdoc |
After a run, the Doc reads:
Northwind project files
2025 Statement of Work.pdf
Brand assets.zip
Kick-off notes.gdoc
Each line is a live link to the file in Drive. The recipient clicks through to exactly the items you listed — nothing more.
Run it
This is an on-demand job, so run it whenever the folder contents change:
- In the Apps Script editor, select
buildFileIndexand click Run. - Approve the authorisation prompt the first time.
- Open the URL from the log, then share the Doc with whoever needs it.
Watch out for
- The links point at the real files. A recipient can only open a link if the file itself is shared with them — the Doc grants no access on its own. Set the files’ sharing first, or this is just a list of names.
- It indexes one folder, not its sub-folders. For a nested structure, see Visualize a deep folder hierarchy, or call this on each sub-folder you care about.
- The Doc is a snapshot, not a live view. Rename or delete a file after generating the index and the Doc will be out of date — re-run it to refresh.
- File order follows whatever Drive returns, which is roughly by creation date, not alphabetical. Sort the paragraphs afterwards if order matters.
À voir aussi
Build a recurring file-delivery system
Drop a fresh report file into a Northwind client folder weekly — they don't even ask.
Mis à jour le 15 déc. 2025
Build a Drive search index in Sheets
Make Northwind's file metadata searchable in a Sheet — like Spotlight for Drive.
Mis à jour le 7 déc. 2025
Build a shared-folder onboarding kit
Auto-grant new Northwind hires the folders they need on day one.
Mis à jour le 29 nov. 2025
Route saved email attachments to project folders
File Gmail attachments into the right Northwind client folder based on subject keywords.
Mis à jour le 25 nov. 2025
Bundle a folder of images into one PDF
Combine Northwind scans into a single deliverable PDF using a generation service.
Mis à jour le 17 nov. 2025