Google Drive full files list
[in http://www.acrosswalls.org/ortext-datalinks/list-google-drive-folder-file-names-urls/]
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:
- Open a new Google Sheet document from the Google account for which you want a Google Drive directory listing.
- In the toolbar for the new Google Sheet, go to Tools -> Script editor
- Create script for: Script as Web App
- A code editor will open. Replace any sample code in the editor with the code below.
- Within the inserted code, replace your-folder with the name of folder for which you want a listing.
- Save the inserted code; application will ask for a file name.
- Run by clicking on the right-pointing triangle in the button bar.
- ‘Authorization required ‘ pop up will appear; grant authorization.
- 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
Post a Comment