Skip to content

Instantly share code, notes, and snippets.

@St3ph-fr
Created August 3, 2012 12:11
Show Gist options
  • Save St3ph-fr/3247014 to your computer and use it in GitHub Desktop.
Save St3ph-fr/3247014 to your computer and use it in GitHub Desktop.
Google Apps Script - List de the public file of the DocsList in Google Apps Script
// #GoogleAppsScript #Gscript #GoogleSpreadsheet
function getPublicFiles(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var docs = DocsList.getFiles(); //Retrieve all the docs.
var listfile = "";
var viewer = new Array;
var owner = "";
var me = Session.getUser().getEmail(); //Get the email of the script owner. Need it to check if you are the owner of the file.
for(var i in docs){
try{
viewer = docs[i].getViewers(); //We have to put this call in a try because sometimes it may return an error.
}catch(e){
viewer = "NA";
}
try{
owner = docs[i].getOwner().getEmail();//We have to put this call in a try because sometimes it may return an error.
}catch(e){
owner = "NA";
}
if(viewer != "NA" && owner == me ){ //If there is wiewer and if you are the owner of the file.
j = 0;
for(j in viewer){
if(viewer[j].getEmail() == "Public"){//Check if the user Public exist in the Viewer.
listfile = listfile + docs[i].getName()+ ", "; // I built a basic list but it can be change in a table for example.
}
}
}
}
Browser.msgBox(listfile); //Just display the list in a message box.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment