Calculating folder sizes in a script

These two posts should have all you need:

Related, counting files instead of sizes: