Last active
May 24, 2018 13:36
-
-
Save JonBons/c3231df4c77ed441a06f to your computer and use it in GitHub Desktop.
Google Sheets - Calculate SUM file size in-between headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//above is inline code from filesize.js | |
function MODPACK_SIZE(column, targetColumn, name) { | |
var sh = SpreadsheetApp.getActiveSheet(); | |
var data = sh.getDataRange().getValues(); | |
var iStart = -1; | |
var iEnd = data.length; | |
// Find start | |
for(n=0; n < data.length; ++n){ | |
if(data[n][column].toString().match(name)==name) { | |
iStart = n + 1; | |
break; | |
} | |
} | |
// Find end | |
for(n=iStart; n < data.length; ++n){ | |
if(data[n][column].toString().match('@')=='@') { | |
iEnd = n - 1; | |
break; | |
} | |
} | |
if (iEnd === data.length) { | |
iEnd = data.length - 1; | |
}; | |
var totalSize = 0; //bytes | |
// Parse in-between | |
if (iStart >= 0) { | |
var ret = ''; | |
for(n=iStart; n < iEnd + 1; ++n){ | |
var exp = data[n][targetColumn].toString().split(' '); | |
var val = Number(exp[0]); | |
var type = exp[1]; | |
switch (type) { | |
case "KB": | |
totalSize += (val * 1000); | |
break; | |
case "MB": | |
totalSize += (val * 1000000); | |
break; | |
case "GB": | |
totalSize += (val * 1000000000); | |
break; | |
} | |
} | |
return filesize(totalSize, {base: 10}); | |
} | |
return 'Failed: ' + name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment