Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

google drive show size folder

"MOSTRAR TAMANHO DAS PASTAS DO GOOGLE DRIVE/SHOW SIZE FOLDER IN GOOGLE DRIVE";
//Source: https://www.alphr.com/get-folder-size-google-drive-folders/


//Acesse: https://script.google.com/macros/s/AKfycbyUvNoXzBMBDE9pnHkLUltliGwjip5x09t3PeTY_1KoXO45F6iz/exec
/*

UPD: veja abaixo

Eu escrevi um script simples para isso. Você pode executá-lo aqui: https://script.google.com/macros/s/AKfycbyUvNoXzBMBDE9pnHkLUltliGwjip5x09t3PeTY_1KoXO45F6iz/exec

(se parar, basta executá-lo novamente e continuará de onde saiu)

Ele criará dois arquivos na raiz do seu Drive, um exibirá o progresso e será excluído após a conclusão do script. Outro é o relatório que lista todas as pastas e tamanhos. Se parece com isso.

*/



//Ou senão copie e cole isso no editor de scripts do Google/Else try copy and paste this in Google Scripts Editor:
function doGet(){
CreateReportFile();
return ContentService.createTextOutput("Report file created in your Drive's root folder");
}

function CreateReportFile() {
  var reportContent = CreateReport();
  DriveApp.createFile('Folder Sizes Report.txt', reportContent);
}

function CreateReport(){
  var reportContent = "";
  var progressFileFound = DriveApp.getRootFolder().searchFiles("title contains 'Getting Folder Sizes,'");
  var progressFile;
  var report=[];
  if(progressFileFound.hasNext()) {
      progressFile = progressFileFound.next();
      var json = progressFile.getBlob().getDataAsString();
      try{
        report = JSON.parse(json);
      } catch(Exception) {
         DriveApp.removeFile(progressFile);
         progressFile = DriveApp.createFile("Getting Folder Sizes, 0 processed...", " ");
      }
    }
  else {
      progressFile = DriveApp.createFile("Getting Folder Sizes, 0 processed...", " ");
    }
  var f = DriveApp.getRootFolder();
  AddFolderToReport(report, f, "/", progressFile);
  DriveApp.removeFile(progressFile);
  reportContent += "TotalSize MB   FilesSize MB   Path 
";
  for(var i=0; i<report.length; i++)
    reportContent += Utilities.formatString("%12.2f ", (report[i].totalSize / (1024*1024))) + Utilities.formatString("%11.2f      ",(report[i].filesSize / (1024*1024))) + report[i].folderPath + "
";
  return reportContent;
}

function AddFolderToReport(report, currentFolder, currentPath, progressFile){
  var report1 = [];
  for(var i=0; i<report.length; i++)
    if(report[i].folderPath == currentPath)
       return report[i].totalSize;

  var fChildren = currentFolder.getFolders();
  var totalSize = 0;
  while(fChildren.hasNext() && currentPath.length < 2000){
    var nextF = fChildren.next();
    totalSize += AddFolderToReport(report, nextF, currentPath + nextF.getName() + "/", progressFile);
  }
  var filesSize = 0;
  var files = currentFolder.getFiles();
  while(files.hasNext()){
    filesSize += files.next().getSize();
  }
  totalSize += filesSize;
  report.push({folderPath: currentPath, filesSize: filesSize, totalSize: totalSize});
  progressFile.setName("Getting Folder Sizes, " + report.length + " processed...");
  progressFile.setContent(JSON.stringify(report));
  return totalSize;
}


//Desenvolvido por: alexkovelsky  (https://webapps.stackexchange.com/users/101141/alexkovelsky)
Comment

PREVIOUS NEXT
Code Example
Javascript :: react navigation 
Javascript :: react final form 
Javascript :: linux command to install standard js 
Javascript :: angular directive to trim input 
Javascript :: Font Size changed from device OS react native app 
Javascript :: get file extension of path extendscript 
Javascript :: socket io add timeout 
Javascript :: javascript merging arrays 
Javascript :: function expression javascript 
Javascript :: discord js check if message author is admin 
Javascript :: arguments object in javascript 
Javascript :: useref in react hooks 
Javascript :: javascript sort multi-dimensional array by column 
Javascript :: alphabetize text in javascript 
Javascript :: material ui navbar 
Javascript :: Get Arrays in sequelize 
Javascript :: schema in mongoose 
Javascript :: Multiple line string in JS 
Javascript :: Object Property Shorthand javascript 
Javascript :: Grunt--example gruntfile.js 
Javascript :: animation end event angular 
Javascript :: js string insert space 
Javascript :: add object to array javascript 
Javascript :: Uncaught (in promise): NotReadableError: Could not start video source 
Javascript :: Selectores de jQuery CSS básicos 
Javascript :: image and video lightbox react 
Javascript :: javascript sleep one second 
Javascript :: javascript form data 
Javascript :: js export options 
Javascript :: temporal dead zone in es6 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =