SHARE
TWEET

Populate spreadsheet with Google Doc file names and size R02

vukisz Jan 29th, 2016 (edited) 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculate() {
  2.   //R01 can be found in http://pastebin.com/2uRe6GR0
  3.   //R02=>
  4.   //var fileList = DocsList.getFiles();
  5.   //var count = fileList.length;
  6.   var files = DriveApp.getFiles();  
  7.   //R02<=
  8.   var file;
  9.   var i;
  10.   var theSheet = SpreadsheetApp.getActiveSheet();
  11.  
  12.  
  13.   theSheet.clear();
  14.   theSheet.getRange(1, 1).setValue("File Name");
  15.   theSheet.getRange(1, 2).setValue("File Location(s)");
  16.   theSheet.getRange(1, 3).setValue("File Size");
  17.   //R02=>
  18.   //for (i=0; i<count; i++)
  19.   i = 0;
  20.   while (files.hasNext())
  21.   //R02<=
  22.   {  
  23.     //R02=>
  24.     //file = fileList[i];
  25.     file = files.next();
  26.     i++;
  27.     //R02<=
  28.     theSheet.getRange(i+2, 1).setValue(file.getName());
  29.     theSheet.getRange(i+2, 3).setValue(file.getSize());    
  30.  
  31.     var folders = file.getParents();
  32.     var folderNames = "";
  33.     //R02=>    
  34.     //var fIdx;
  35.     //for (fIdx in folders)
  36.     //{
  37.     //  folderNames = folders[fIdx].getName() + "; " + folderNames;
  38.     //}
  39.     while (folders.hasNext())
  40.     {
  41.       var folder = folders.next();
  42.       folderNames = folder.getName() + "\\" + folderNames;
  43.       if(!folders.hasNext())
  44.       {
  45.         folders = folder.getParents();
  46.       }
  47.     }    
  48.     //R02<=
  49.     theSheet.getRange(i+2, 2).setValue(folderNames);
  50.   }
  51.  
  52.   theSheet.sort(3, false);
  53.   //R02=>  
  54.   //theSheet.getRange(2, 3, count, 1).setNumberFormat("#,##0")
  55.   theSheet.getRange(2, 3, i+2, 1).setNumberFormat("#,##0")
  56.   //R02=>  
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top