-
-
Save JavierCane/28f7307ceeaf6464431c1418b598a817 to your computer and use it in GitHub Desktop.
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",
"[email protected]"
];
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.