Find Files Shared with Anyone with the Link in Google Drive
How can I find every file in a Google Drive folder that is shared with anyone who has the link?
Bind an Apps Script to a review spreadsheet and point it at a folder. It checks every file in the folder and its subfolders with getSharingAccess() and lists the ones set to ANYONE or ANYONE_WITH_LINK, with the link permission, owner and URL. It only reports; you change sharing yourself in Drive after review.
An Apps Script can check every file under a Drive folder and list the ones that anyone with the link can open. It reads each file’s general access setting, keeps only the public and link-shared ones, and writes them to a new spreadsheet tab. It never changes a sharing setting. Someone reviews the list and fixes what needs fixing by hand.
Link sharing is easy to turn on and easy to forget. A contract sent to one supplier last spring, a payroll export shared for a quick look, a folder of ID scans for a visa application: any of them can stay open to anyone holding the link long after the job is done.
Which sharing settings does the audit flag?
Apps Script describes a file’s general access with the DriveApp.Access enum, and File.getSharingAccess() returns one of its values. The Access enum reference lists five.
| Access value | Google’s description | Flagged by this audit |
|---|---|---|
ANYONE |
Anyone on the Internet can find and access. No sign-in required. | Yes |
ANYONE_WITH_LINK |
Anyone who has the link can access. No sign-in required. | Yes |
DOMAIN |
People in your domain can find and access. Sign-in required. | No |
DOMAIN_WITH_LINK |
People in your domain who have the link can access. Sign-in required. | No |
PRIVATE |
Only people explicitly granted permission can access. Sign-in required. | No |
The two flagged values are the ones that need no sign-in, which is why they matter most. Domain settings only apply to Google Workspace accounts and still require a company login, so the script leaves them out. If you want those too, add them to the FLAGGED list in the code.
For each flagged file the report also shows getSharingPermission(), which the File reference describes as the permission given to those users beyond people explicitly granted access. In practice that tells you whether a link holder can view, comment or edit. The values come from the Permission enum. An EDIT link is the most urgent kind to look at: Google’s reference notes that editors can change the file’s sharing settings unless that has been turned off.
How do you point the audit at a folder?
Use a separate spreadsheet for the audit so the findings are not mixed with other work, and limit who can open it.
- Create a spreadsheet, for example
Morgan Sample sharing review, and open Extensions, then Apps Script. - Paste the script from the next section and save it.
- Copy the folder ID from the folder’s Drive address: the part after
/folders/, without anything from a?onward. - Add the property. In Project Settings, under Script Properties, add
AUDIT_FOLDER_IDwith the folder ID as its value. - Apply the manifest shown later in this guide, so the project can only read Drive.
- Run
auditLinkSharingand approve the prompt with an account that can open the whole folder tree. - Open the new tab, named
Link auditplus the run time.
The script sees only what the authorizing account can see. A file inside the folder that has not been shared with that account will not appear, whatever its link setting. The folder owner, or someone with access to everything in it, is the right person to run it.
What does the report-only sharing audit script look like?
The script walks the folder tree with a queue: it takes a folder, checks its files, adds its subfolders, and moves on. It compares each file’s access value against the flagged list and collects matches. Rows are written to a new tab in one call at the end.
const FLAGGED = [DriveApp.Access.ANYONE, DriveApp.Access.ANYONE_WITH_LINK];
const TIME_LIMIT_MS = 5 * 60 * 1000; // the per-run limit is 6 minutes
function auditLinkSharing() {
const started = Date.now();
const ss = SpreadsheetApp.getActiveSpreadsheet();
if (!ss) {
throw new Error('Run this from Extensions > Apps Script in a spreadsheet.');
}
const folderId = (PropertiesService.getScriptProperties()
.getProperty('AUDIT_FOLDER_ID') || '').trim();
if (!folderId) {
throw new Error('Set AUDIT_FOLDER_ID in Script Properties.');
}
const top = DriveApp.getFolderById(folderId);
const queue = [{ folder: top, path: top.getName() }];
const found = [];
let checked = 0;
let outOfTime = false;
while (queue.length > 0 && !outOfTime) {
const item = queue.shift();
const files = item.folder.getFiles();
while (files.hasNext()) {
if (Date.now() - started > TIME_LIMIT_MS) {
outOfTime = true;
break;
}
const file = files.next();
if (file.isTrashed()) continue;
checked += 1;
const access = file.getSharingAccess();
if (!FLAGGED.some(a => a == access)) continue;
const owner = file.getOwner();
found.push([
safeText(file.getName()),
safeText(item.path),
String(access),
String(file.getSharingPermission()),
owner ? (owner.getEmail() || '') : '',
file.getLastUpdated(),
file.getUrl(),
'' // Decision column for the reviewer
]);
}
if (outOfTime) break;
const subs = item.folder.getFolders();
while (subs.hasNext()) {
const sub = subs.next();
if (!sub.isTrashed()) {
queue.push({ folder: sub, path: item.path + '/' + sub.getName() });
}
}
}
const header = ['Name', 'Folder path', 'General access', 'Link permission',
'Owner', 'Last updated', 'URL', 'Decision'];
const values = [header].concat(found);
values.push(['Checked ' + checked + ' files' + (outOfTime
? '. INCOMPLETE: stopped at the time limit with folders left to check.'
: '. Audit complete.'), '', '', '', '', '', '', '']);
const stamp = Utilities.formatDate(new Date(), Session.getScriptTimeZone(),
'yyyy-MM-dd HHmm');
let name = 'Link audit ' + stamp;
for (let n = 2; ss.getSheetByName(name); n++) {
name = 'Link audit ' + stamp + ' (' + n + ')';
}
const sheet = ss.insertSheet(name);
if (values.length > sheet.getMaxRows()) {
sheet.insertRowsAfter(sheet.getMaxRows(), values.length - sheet.getMaxRows());
}
sheet.getRange(1, 1, values.length, header.length).setValues(values);
sheet.setFrozenRows(1);
ss.toast(found.length + ' link-shared files found', 'Sharing audit', 8);
}
// Keeps a name that starts with "=" from being treated as a formula.
function safeText(value) {
return /^[=+\-@]/.test(value) ? "'" + value : value;
}
There is no call in this script that changes sharing. It reads getSharingAccess(), getSharingPermission(), getOwner(), getLastUpdated() and getUrl(), and that is all it asks of each file. The manifest in a later section makes that a hard limit rather than a promise.
The script checks the clock before each file. Google’s quotas page gives a script runtime of six minutes per execution, so the script stops at five, writes whatever it found, and marks the last row INCOMPLETE. A large tree may need one run per subfolder.
What does a finished link audit tab show?
A sample run over a fictional Office folder might produce this tab. The last column is left blank for the reviewer.
| Name | Folder path | General access | Link permission | Owner | Decision |
|---|---|---|---|---|---|
| Supplier contract 2025.pdf | Office/Contracts | ANYONE_WITH_LINK | VIEW | avery@example.com | |
| Payroll export March | Office/Finance | ANYONE_WITH_LINK | EDIT | riley@example.com | |
| Public price list | Office/Sales | ANYONE | VIEW | morgan@example.com | |
| Checked 214 files. Audit complete. |
Work through it in a set order. Fix EDIT links first, since anyone holding them can change the file. Then look at anything with personal, financial or legal content. Files that are meant to be public, like the price list above, can be marked Keep in the Decision column so the next review goes faster.
To restrict a file, open it from the URL column. Google’s sharing help page describes the steps: click Share, open the dropdown under General access, and choose who can use the link. Picking Restricted means only people who have been given access can open the file. Anyone given access by name can still open it.
The owner column can be blank when Drive does not return an owner email for that file. In that case, ask whoever runs the shared folder.
Can Drive’s own search find link-shared files?
Partly. Google’s Drive search help lists a sharedwith operator with sharedwith:public as one of its examples, and sharedwith:external for items explicitly shared with people outside a Workspace organization. The help page does not spell out exactly which link settings sharedwith:public matches, so treat its results as a starting point and check a known link-shared file appears before relying on it.
The search also covers your whole Drive rather than one folder tree, and it gives you a list on screen rather than something you can sort, annotate and hand to a colleague. The script fills that gap. For a small folder, opening each file’s Share dialog and reading the General access line works too.
When should you not rely on this audit?
The audit is a snapshot of one folder tree, seen through one account. It will not catch:
- Files outside the folder. Anything shared from someone’s My Drive root or another folder needs its own run.
- Files the running account cannot see. Hidden files cannot be checked.
- Sharing on the folders themselves. The script reads the access setting of files, not of folders. Open the Share dialog on the top folders and read their General access line by hand as well.
- Changes after the run. Run it again after a cleanup, and on a schedule that suits how often files are shared.
Keep the audit spreadsheet restricted. It lists file names and links to exactly the files that are open to anyone, which makes it a useful document for the wrong reader.
For related Drive reports, finding same-name files in a Drive folder uses a similar read-only pattern on a single folder, and renaming invoice PDFs from a tracking sheet shows how to make Drive changes safely with a dry run when you do want a script to act. More tools for running a small office sit under the small-business stack topic.