Friday, December 6, 2013

Google App Script: How to read your Google Drive statistics?

Google App Script is cloud based Scripting language. It can be used use to design solutions which can access and leverage the Google services such as Gmail, Spreadsheet, Google Drive, Google BigQuery, Google Calendar etc.

In this post we will learn how we can write a simple script to get statistics about our Google drive. How many files, folders etc we have stored in our Google Drive.

To start with we need to go to Google Apps Script. We need to select a Blank Project.

This will open the Google App Script editor. We will delete all the code and paste the following code.

function ReadGoogleDrive() {
  
  /* The Purpose of this App Script is read Google Drive statistics */
  
  var myTotalFiles=DocsList.getAllFiles().length;
  var myTotalFolders=DocsList.getAllFolders().length;

  var myTotlaSperadsheetFile=DocsList.getFilesByType('Spreadsheet').length;
  var myTotlaPresentationFile=DocsList.getFilesByType('Presentation').length;
  var myTotlaDrawFile=DocsList.getFilesByType('Drawing').length;
  var myTotlaFormFile=DocsList.getFilesByType('Form').length;
  var myTotlaDocumentFile=DocsList.getFilesByType('Document').length;
  
  
  Logger.log("Google Drive Statistics for " + Session.getActiveUser());
  Logger.log("All Files in Google Drive: " + myTotalFiles);
  Logger.log("All Folders in Google Drive: " + myTotalFolders);
  Logger.log("All Spreadsheet Files in Google Drive: " + myTotlaSperadsheetFile);
  Logger.log("All Presentation Files in Google Drive: " + myTotlaPresentationFile);
  Logger.log("All Drawing Files in Google Drive: " + myTotlaDrawFile);
  Logger.log("All Forms Files in Google Drive: " + myTotlaDrawFile);
  Logger.log("All Documents Files in Google Drive: " + myTotlaDrawFile);
  
  
}

Next we need to click on Run

For the first time it will ask for the Authorization to run the Script. We need to click on Continue.

Google will show the Permission window and request for permission so that it can pull data from Google services such as Google Drive,and Google Account.

Click on Accept. Again click on the Run button. This time the script will run and interact with the Google Drive and Google Account and pull out the Google Drive statistics. To see the result of your Google App Script go to View->Logs

For more Google App Script visit the Google App Script section.

Popular Posts

Real Time Web Analytics