-
-
Save rzrbld/ba50a0f51b081a5699cb1d4996e4925a to your computer and use it in GitHub Desktop.
google script that lists a lot of info about the files in a particular folder/sub folder structure including viewers, editors, and sharing permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function listFolders(folder) { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
sheet.appendRow(["Name","Folder Name" ,"Sharing Access", "Sharing Permission", "Get Editors", "Get Viewers", "Date", "Size", "URL", "Download", "Description", "Type"]); //writes the headers | |
// var folder = DriveApp.getFolderById("ID");//that long chunk of random numbers/letters in the URL when you navigate to the folder | |
var folders = DriveApp.getFolders(); | |
while (folders.hasNext()) { | |
var folder = folders.next(); | |
Logger.log(folder.getName()); | |
var files = folder.getFiles();//initial loop on loose files w/in the folder | |
var cnt = 0; | |
var file; | |
while (files.hasNext()) { | |
var file = files.next(); | |
var listEditors = file.getEditors(); //gets the editor email(s), doesn't show your own as it's assumed | |
var editors = []; | |
for (var cnt = 0; cnt < listEditors.length; cnt++) { | |
editors.push(listEditors[cnt].getEmail()); | |
Logger.log(editors); | |
}; | |
var listViewers = file.getViewers(); //gets the viewer email(s) | |
var viewers = []; | |
for (var cnt = 0; cnt < listViewers.length; cnt++) { | |
viewers.push(listViewers[cnt].getEmail()); | |
Logger.log(viewers); | |
} | |
cnt++; //data chunk pushes all the file info to the ss | |
data = [ | |
file.getName(), | |
folder.getName(), | |
file.getSharingAccess(), | |
file.getSharingPermission(), | |
editors.toString(), | |
viewers.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); | |
}; | |
var subfolders = folder.getFolders(); //same thing as above but for all the subfolders in the folder | |
while (subfolders.hasNext()) { | |
//Logger.log(folder); | |
var name = subfolders.next(); | |
var files = name.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()); | |
Logger.log(editors); | |
}; | |
var listViewers = file.getViewers(); | |
var viewers = []; | |
for (var cnt = 0; cnt < listViewers.length; cnt++) { | |
viewers.push(listViewers[cnt].getEmail()); | |
Logger.log(viewers); | |
} | |
cnt++; | |
data = [ | |
file.getName(), | |
folder.getName(), | |
file.getSharingAccess(), | |
file.getSharingPermission(), | |
editors.toString(), | |
viewers.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); | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment