Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Created November 3, 2020 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waynegraham/260961e3dc83e80479fc8d9ad954da4f to your computer and use it in GitHub Desktop.
Save waynegraham/260961e3dc83e80479fc8d9ad954da4f to your computer and use it in GitHub Desktop.
List links in a GoogleDrive directory

This is from https://webapps.stackexchange.com/questions/88769/get-share-link-of-multiple-files-in-google-drive-to-put-in-spreadsheet.

In a Google Sheet, click on Tools->Script Editor

Add the following function (be sure to change the to the ID needed):

function myFunction() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var s=ss.getActiveSheet();
  var c=s.getActiveCell();
  var fldr=DriveApp.getFolderById("<id>");
  var files=fldr.getFiles();
  var names=[],f,str;
  while (files.hasNext()) {
    f=files.next();
    str='=hyperlink("' + f.getUrl() + '","' + f.getName() + '")';
    names.push([str]);
  }
  s.getRange(c.getRow(),c.getColumn(),names.length).setFormulas(names);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment