Script: All files in Drive

A very useful script. Lists out all files in your Google Drive to a Google Spreadsheet

Script

function allFilesInDrive() {

// Log the name of every file in the user's Drive.
// its type & url as well

var files = DriveApp.getFiles();
var ss = SpreadsheetApp.openById('1Hq1eFGYCUzf82bvUC_yM9abG7Bt9sY30xGIX-pmUK2c');
var sheet = ss.getSheetByName("Sheet1");
var range = sheet.getDataRange();
var data = range.getValues();
var count = 1;


while (files.hasNext()) {
var file = files.next();

Logger.log(data);
Logger.log(file.getName());
Logger.log(file.getMimeType());
Logger.log(file.getUrl());
sheet.getRange(count, 1).setValue(file.getName());
sheet.getRange(count, 2).setValue(file.getUrl());
sheet.getRange(count, 3).setValue(file.getAccess('office@sijokuruvilla.in'));

count++;


}

}

Note

  • Spreadhseet ID and the sheet name to be copied accurately.
  • Reference: Output that gets captured in the spreadsheet can be viewed from the screenshot below


The script takes a fair amount of time to execute. So if you wish to try this out quickly you may make use of the following script. In this the output ie list of files in Drive can be viewed in the Logger window as against the Spreadsheet. The following one was also the first script I managed to put together. Took Jibin's help to then bring it together in the above form. 


function allFilesInDrive() {

    // Log the name of every file in the user's Drive.

    // its type & url as well

  

  var files = DriveApp.getFiles();

  

  while (files.hasNext()) {

  var file = files.next();

  Logger.log(file.getName());

    Logger.log(file.getMimeType());

    Logger.log(file.getUrl());

}  

}