Google Drive full files list

List Google Drive Folder File Names and URLs to a Google Sheet

This Google Apps script produces a new Google sheet containing the list of files in a Google Drive folder, along with their URLs on Google Drive. Such a file is helpful for creating a datalinks manifest for importing datalinks into an ortext.
Steps for installing and running the Google Apps script:
  1. Open a new Google Sheet document from the Google account for which you want a Google Drive directory listing.
  2. In the toolbar for the new Google Sheet, go to Tools -> Script editor
  3. Create script for: Script as Web App
  4. A code editor will open. Replace any sample code in the editor with the code below.
  5. Within the inserted code, replace your-folder with the name of folder for which you want a listing.
  6. Save the inserted code; application will ask for a file name.
  7. Run by clicking on the right-pointing triangle in the button bar.
  8. ‘Authorization required ‘ pop up will appear; grant authorization.
  9. A listing of the files in the specified folder, along with URLs for those files, will then appear in your My Drive as a Google Sheet named listing of folder {your-folder}
The Google Apps script code for listing a folder with URLs to a new Google Sheet:
// replace your-folder below with the folder for which you want a listing
function listFolderContents() {
  var foldername = 'your-folder';
  var folderlisting = 'listing of folder ' + foldername;
  
  var folders = DriveApp.getFoldersByName(foldername)
  var folder = folders.next();
  var contents = folder.getFiles();
  
  var ss = SpreadsheetApp.create(folderlisting);
  var sheet = ss.getActiveSheet();
  sheet.appendRow( ['name', 'link'] );
  
  var file;
  var name;
  var link;
  var row;
  while(contents.hasNext()) {
    file = contents.next();
    name = file.getName();
    link = file.getUrl();
    sheet.appendRow( [name, link] );     
  }  
};

[in http://www.acrosswalls.org/ortext-datalinks/list-google-drive-folder-file-names-urls/]

Comments

Popular posts from this blog

Add GitHub Repository to DBeaver CE Secured with SSH Protocol

Keyboard Shortcut to "Toggle Line Comments" in DBeaver

DBeaver Shortcuts