Guest User

Populate spreadsheet with Google Doc file names and sizes

a guest
Jul 15th, 2011
1,309
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculate() {
  2.   var fileList = DocsList.getFiles();
  3.   var count = fileList.length;
  4.   var file;
  5.   var i;
  6.   var theSheet = SpreadsheetApp.getActiveSheet();
  7.  
  8.   theSheet.clear();
  9.   theSheet.getRange(1, 1).setValue("File Name");
  10.   theSheet.getRange(1, 2).setValue("File Location(s)");
  11.   theSheet.getRange(1, 3).setValue("File Size");
  12.   for (i=0; i<count; i++)
  13.   {
  14.     file = fileList[i];
  15.     theSheet.getRange(i+2, 1).setValue(file.getName());
  16.     theSheet.getRange(i+2, 3).setValue(file.getSize());    
  17.  
  18.     var folders = file.getParents();
  19.     var folderNames = "";
  20.     var fIdx;
  21.     for (fIdx in folders)
  22.     {
  23.       folderNames = folders[fIdx].getName() + "; " + folderNames;
  24.     }
  25.     theSheet.getRange(i+2, 2).setValue(folderNames);
  26.   }
  27.  
  28.   theSheet.sort(3, false);
  29.   theSheet.getRange(2, 3, count, 1).setNumberFormat("#,##0")
  30. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×