Google-drive – Get share link of multiple files in Google Drive to put in spreadsheet

google-drivelinks

I've got 200+ jpegs in a folder and need shareable links for each jpeg in a spreadsheet. Is there a way to do this without doing the right clicking thing for each image individually?

Best Answer

With a very large number of files (50+), a method without painful clicking is the following:

  1. Open the desired Google Drive folder and get its ID in the URL from the browser location bar: https://drive.google.com/drive/u/0/folders/<id>

  2. Open a new Google Sheet and navigate Tools > Script editor. In the new script, put (replace the <id> in the code):

    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);
    }
    
  3. Save the script and grant permissions

  4. Run the script

If you revisit the Google Sheet, it should now contain the list of URLs of the files.

(I stole most of this from https://productforums.google.com/forum/#!topic/docs/0ilSDjhFnHI)