Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function listDocs() {
var folderid = '{any folder id}';
var folder = DriveApp.getFolderById(folderid)
var contents = folder.getFiles();
var file;
var files = [];
while(contents.hasNext()) {
file = contents.next()
if (!file.getName().match('Template to exclude')) {
files.push(file)
}
}
return files
};
function writeDocsIntoSheet() {
// Replace this with a sheet id of your own if you can't get permission to write to this one
var sheetid = '1PjxE4V-some-sheet-id'
var ss = SpreadsheetApp.openById(sheetid);
var sheet = ss.getActiveSheet();
sheet.clearContents()
sheet.appendRow( ['link', 'Name', 'URI'] );
var file;
var name;
var link;
var html;
var row;
var files = listDocs()
for (var i in files) {
var file = files[i];
name = file.getName();
link = file.getUrl();
html = '=HYPERLINK("' + link + '","' + name + '")'
sheet.appendRow( [html, name, link] );
}
}
function doGet(e) {
var html = "<table>"
var files = listDocs()
// sort by filename
files = files.sort(function(a,b) { return (a.getName() > b.getName() ? -1 : (a.getName() < b.getName() ? 1 : 0 )) });
for (var i in files) {
var file = files[i];
name = file.getName();
link = file.getUrl();
html += '<tr><td><a href="' + link + '">' + name + '</a></td></tr>'
html += "\n"
}
html += "</table>"
return HtmlService.createHtmlOutput(html);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment