How to add sums of two different folder sets?

Happy Friday Bigfixers,

Would someone be so kind as to point me in the right direction for an analysis where I’d like to retrieve the sum of two different sets of folders, add them together and aforementioned analysis provides the result.

if exists (folder "c:\users\all users\fireeye") then ((if (0<(it / (1024*1024*1024*1024))) then (it / (1024*1024*1024*1024)) as string & "TB" else if (0<(it / (1024*1024*1024))) then (it / (1024*1024*1024)) as string & "GB" else if (0<(it / (1024*1024))) then (it / (1024*1024)) as string & "MB" else if (0<(it / (1024))) then (it / (1024)) as string & "KB" else (it as string & "B")) of (sum of sizes of descendants of folder "c:\users\all users\fireeye")) else ERROR "All Users\Fireeye dir not found"

“+”

if exists (folder "c:\programdata\fireeye") then ((if (0<(it / (1024*1024*1024*1024))) then (it / (1024*1024*1024*1024)) as string & "TB" else if (0<(it / (1024*1024*1024))) then (it / (1024*1024*1024)) as string & "GB" else if (0<(it / (1024*1024))) then (it / (1024*1024)) as string & "MB" else if (0<(it / (1024))) then (it / (1024)) as string & "KB" else (it as string & "B")) of (sum of sizes of descendants of folder "c:\programdata\fireeye")) else ERROR "FirEeye dir not found"

= Some number much higher than it should be if it were working properly.

Thanks very much!

Your two individual results can’t just be added because you are returning strings - and they are not even necessarily the same order of magnitude

sum of sizes of descendants of folders ( "c:\users\all users\fireeye"; "c:\programdata\fireeye")

It doesn’t have explicit error checking, but an unfound folder will return 0 size.

It does have to be noted that ‘descendants’ should be used with care - it could be an expensive (slow) property to evaluate.

1 Like