-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inventory of Shared Files in Drive.gs
45 lines (39 loc) · 1.37 KB
/
Inventory of Shared Files in Drive.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* A Google Script to be run as a Custom Function in a Sheet that
* finds all files that are shared and
* displays the file's: name, URL, access, viewers' email addresses, editors' email addresses
* https://developers.google.com/apps-script/guides/sheets/functions
*/
function catalogDrive() {
var files = DriveApp.getFiles();
var sharedFiles = new Array();
while (files.hasNext()) {
var file = files.next();
var listOfEditors = (file.getEditors().length > 0) ? file.getEditors().map(it => it.getEmail()).toString() : "";
var listOfViewers = (file.getViewers().length > 0) ? file.getViewers().map(it => it.getEmail()).toString() : "";
if (listOfEditors.length || listOfViewers.length) {
var sharingAccess;
try {
sharingAccess = file.getSharingAccess();
} catch (err) {
sharingAccess = "ERROR";
}
sharedFiles.push(
[
file.getName(),
file.getUrl(),
sharingAccess,
listOfViewers.toString(),
listOfEditors.toString()
]
);
}
}
/* Display the results */
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.clear();
sheet.setName("Shared Files");
sheet.appendRow(["file name", "URL", "Sharing", "Editors", "Viewers"]);
sheet.setFrozenRows(1);
sheet.getRange(2, 1, sharedFiles.length, 5).setValues(sharedFiles);
}