Want more features on Pastebin? Sign Up, it's FREE!
Guest

Populate spreadsheet with Google Doc file names and sizes

By: a guest on Jul 15th, 2011  |  syntax: JavaScript  |  size: 0.85 KB  |  views: 781  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data