Forked from woodwardtw/tellmeyoursecrets.js
Last active
February 21, 2024 11:54
Google Spreadsheet script that lists all the shared documents inside a specified folder and all its subfolders recursively. Skips out the documents shared internally (with specified email addresses)
// iterative approach
function recursiveListSharedFiles(rootFolder, sheet) {
const stack = [];
stack.push(rootFolder);
while(stack.length !== 0){
const folder = stack.shift();
listSharedFiles(folder, sheet);
const subfolders = folder.getFolders();
while (subfolders.hasNext()) {
stack.push(subfolders.next());
}
}
}
Thanks. I'd add in line 43 another line to allow filtering by domain:
function filterInternalEditors(file) {
const internalEmails = [
"@gmail.com",
"fullemail@gmail.com"
];
const editorEmails = file.getEditors().map(e => e.getEmail());
return editorEmails.filter(editorEmail =>
!internalEmails.includes(editorEmail) &&
!internalEmails.includes(editorEmail.slice(editorEmail.indexOf('@')))); //Line added
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the correct recursive approach imo.
You could also call
const folder = DriveApp.getRootFolder();
to scan the entire drive at line 5.One can also add
file.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.EDIT);
at line 69 to just close these loose files immediately after documenting. But, it should be checked whether you own the file or they are not just shared with you by others. It is possible to move shared links (files or folders) under your Google drive.