Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JackDanger/7d075d91acbdf0f161e530b2d43d076e to your computer and use it in GitHub Desktop.
Save JackDanger/7d075d91acbdf0f161e530b2d43d076e to your computer and use it in GitHub Desktop.
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