You can simply add dimensions recursively (the following batch file):
@echo off set size=0 for /r %%x in (folder\*) do set /a size+=%%~zx echo %size% Bytes
However, this has several problems because cmd limited to 32-bit signed integer arithmetic. Thus, it will have sizes above 2 GB incorrectly 1 . In addition, it will probably count symbolic links and transitions several times, so at best itβs the upper bound and not the true size (you will have this problem with any tool).
An alternative is PowerShell:
Get-ChildItem -Recurse | Measure-Object -Sum Length
or shorter:
ls -r | measure -s Length
If you want it more beautiful:
switch((ls -r|measure -s Length).Sum) { {$_ -gt 1GB} { '{0:0.0} GiB' -f ($_/1GB) break } {$_ -gt 1MB} { '{0:0.0} MiB' -f ($_/1MB) break } {$_ -gt 1KB} { '{0:0.0} KiB' -f ($_/1KB) break } default { "$_ bytes" } }
You can use this directly from cmd :
powershell -noprofile -command "ls -r|measure -s Length"
1 I have a partially processed bignum library in batch files somewhere that at least has the right to an arbitrary number of integers. I really have to let him go, I think :-)
Joey Oct 10 '12 at 7:16 2012-10-10 07:16
source share