Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Apps Script that lists a lot of info about the files in a particular folder/sub folder structure including viewers, editors, and sharing access type
function listFolders(folder) {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(["Folder Name" ,"Name","Sharing Access", "Get Editors", "Get Viewers", "Date", "URL"]);
folderID = "ID"
listFolder(sheet, folderID)
}
function listFolder(sheet, folderID) {
var folder = DriveApp.getFolderById(folderID);
addRootFilesToSheet(sheet, folder)
addSubFoldersContentToSheet(sheet, folder)
}
function addRootFilesToSheet(sheet, folder) {
var files = folder.getFiles();
var cnt = 0;
var file;
while (files.hasNext()) {
var file = files.next();
var listEditors = file.getEditors();
var editors = [];
for (var cnt = 0; cnt < listEditors.length; cnt++) {
editors.push(listEditors[cnt].getEmail());
};
var listViewers = file.getViewers();
var viewers = [];
for (var cnt = 0; cnt < listViewers.length; cnt++) {
viewers.push(listViewers[cnt].getEmail());
}
cnt++;
data = [
folder.getName(),
file.getName(),
file.getSharingAccess(),
editors.toString(),
viewers.toString(),
file.getDateCreated(),
file.getUrl(),
];
sheet.appendRow(data);
}
}
function addSubFoldersContentToSheet(sheet, folder) {
var subfolders = folder.getFolders();
Logger.log(subfolders)
while (subfolders.hasNext()) {
var subfolder = subfolders.next();
Logger.log(subfolder.getName())
var files = subfolder.getFiles();
var cnt = 0;
var file;
while (files.hasNext()) {
var file = files.next();
var listEditors = file.getEditors();
var editors = [];
for (var cnt = 0; cnt < listEditors.length; cnt++) {
editors.push(listEditors[cnt].getEmail());
};
var listViewers = file.getViewers();
var viewers = [];
for (var cnt = 0; cnt < listViewers.length; cnt++) {
viewers.push(listViewers[cnt].getEmail());
}
cnt++;
data = [
folder.getName() + " / " + subfolder.getName(),
file.getName(),
file.getSharingAccess(),
editors.toString(),
viewers.toString(),
file.getDateCreated(),
file.getUrl(),
];
sheet.appendRow(data);
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment