|
function start() { |
|
const sheet = SpreadsheetApp.getActiveSheet(); |
|
sheet.appendRow(["Name", "Sharing Access", "Sharing Permission", "Get Editors", "Get Viewers", "Date", "Size", "URL", "Download", "Description", "Type"]); |
|
|
|
const folder = DriveApp.getRootFolder(); |
|
|
|
recursiveListSharedFiles(folder, sheet); |
|
} |
|
|
|
function recursiveListSharedFiles(folder, sheet) { |
|
listSharedFiles(folder, sheet); |
|
|
|
const subfolders = folder.getFolders(); |
|
|
|
while (subfolders.hasNext()) { |
|
recursiveListSharedFiles(subfolders.next(), sheet); |
|
} |
|
} |
|
|
|
function listSharedFiles(folder, sheet) { |
|
const files = folder.getFiles(); |
|
|
|
while (files.hasNext()) { |
|
const file = files.next(); |
|
const externalEditorEmails = filterInternalEditors(file); |
|
|
|
if (isOnlySharedInternally(externalEditorEmails, file)) { |
|
continue; |
|
} |
|
|
|
appendRow(externalEditorEmails, file, sheet) |
|
} |
|
} |
|
|
|
function filterInternalEditors(file) { |
|
const internalEmails = [ |
|
"[email protected]", |
|
"[email protected]" |
|
]; |
|
|
|
const editorEmails = file.getEditors().map(e => e.getEmail()); |
|
|
|
return editorEmails.filter(editorEmail => !internalEmails.includes(editorEmail)); |
|
} |
|
|
|
function isOnlySharedInternally(externalEditorEmails, file) { |
|
return externalEditorEmails.length === 0 |
|
&& file.getViewers().length === 0 |
|
&& file.getSharingAccess() === DriveApp.Access.PRIVATE; |
|
} |
|
|
|
function appendRow(editorEmails, file, sheet) { |
|
const viewerEmails = file.getViewers().map(v => v.getEmail()); |
|
|
|
data = [ |
|
file.getName(), |
|
file.getSharingAccess(), |
|
file.getSharingPermission(), |
|
editorEmails.toString(), |
|
viewerEmails.toString(), |
|
file.getDateCreated(), |
|
file.getSize(), |
|
file.getUrl(), |
|
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(), |
|
file.getDescription(), |
|
file.getMimeType(), |
|
]; |
|
|
|
sheet.appendRow(data); |
|
} |